MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / test_issue_363

Method test_issue_363

pymysql/tests/test_issues.py:455–500  ·  view source on GitHub ↗

Test binary / geometry types.

(self)

Source from the content-addressed store, hash-verified

453 cur.executemany(usql, args=(values, values, values))
454
455 def test_issue_363(self):
456 """Test binary / geometry types."""
457 conn = pymysql.connect(charset="utf8", **self.databases[0])
458 self.safe_create_table(
459 conn,
460 "issue363",
461 "CREATE TABLE issue363 ( "
462 "id INTEGER PRIMARY KEY, geom LINESTRING NOT NULL /*!80003 SRID 0 */, "
463 "SPATIAL KEY geom (geom)) "
464 "ENGINE=MyISAM",
465 )
466
467 cur = conn.cursor()
468 query = (
469 "INSERT INTO issue363 (id, geom) VALUES"
470 "(1998, ST_GeomFromText('LINESTRING(1.1 1.1,2.2 2.2)'))"
471 )
472 cur.execute(query)
473
474 # select WKT
475 query = "SELECT ST_AsText(geom) FROM issue363"
476 cur.execute(query)
477 row = cur.fetchone()
478 self.assertEqual(row, ("LINESTRING(1.1 1.1,2.2 2.2)",))
479
480 # select WKB
481 query = "SELECT ST_AsBinary(geom) FROM issue363"
482 cur.execute(query)
483 row = cur.fetchone()
484 self.assertEqual(
485 row,
486 (
487 b"\x01\x02\x00\x00\x00\x02\x00\x00\x00"
488 b"\x9a\x99\x99\x99\x99\x99\xf1?"
489 b"\x9a\x99\x99\x99\x99\x99\xf1?"
490 b"\x9a\x99\x99\x99\x99\x99\x01@"
491 b"\x9a\x99\x99\x99\x99\x99\x01@",
492 ),
493 )
494
495 # select internal binary
496 cur.execute("SELECT geom FROM issue363")
497 row = cur.fetchone()
498 # don't assert the exact internal binary value, as it could
499 # vary across implementations
500 self.assertTrue(isinstance(row[0], bytes))
501
502 def test_issue_1206(self):
503 conn = pymysql.connect(charset="utf8", **self.databases[0])

Callers

nothing calls this directly

Calls 5

safe_create_tableMethod · 0.80
cursorMethod · 0.80
executeMethod · 0.80
connectMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected