def test_boolean_roundtrip_reflected(self, connection, boolean_table,
                                         store, expected):
        table = Table("mysql_bool", MetaData(), autoload_with=connection)
        eq_(colspec(table.c.b3), "b3 TINYINT(1)")
        eq_regex(colspec(table.c.b4), r"b4 TINYINT(?:\(1\))? UNSIGNED")

        table = Table(
            "mysql_bool",
            MetaData(),
            Column("b1", BOOLEAN),
            Column("b2", Boolean),
            Column("b3", BOOLEAN),
            Column("b4", BOOLEAN),
            autoload_with=connection,
        )
        eq_(colspec(table.c.b3), "b3 BOOL")
        eq_(colspec(table.c.b4), "b4 BOOL")

        expected = expected or store
        connection.execute(table.insert().values(store))
        row = connection.execute(table.select()).first()
        eq_(list(row), expected)
        for i, val in enumerate(expected):
            if isinstance(val, bool):
                self.assert_(val is row[i])
Beispiel #2
0
    def test_year(self):
        """Exercise YEAR."""

        year_table = Table(
            "mysql_year",
            self.metadata,
            Column("y1", mysql.MSYear),
            Column("y2", mysql.MSYear),
            Column("y3", mysql.MSYear),
            Column("y5", mysql.MSYear(4)),
        )

        for col in year_table.c:
            self.assert_(repr(col))
        year_table.create()
        reflected = Table("mysql_year", MetaData(testing.db), autoload=True)

        for table in year_table, reflected:
            with testing.db.connect() as conn:
                conn.execute(table.insert(["1950", "50", None, 1950]))
                row = conn.execute(table.select()).first()
                eq_(list(row), [1950, 2050, None, 1950])
                conn.execute(table.delete())
                self.assert_(colspec(table.c.y1).startswith("y1 YEAR"))
                eq_regex(colspec(table.c.y5), r"y5 YEAR(?:\(4\))?")
Beispiel #3
0
 def test_exception_format_unexpected_member_parameter(self):
     # test that if the parameters aren't any known type, we just
     # run through repr()
     exception = tsa.exc.IntegrityError("foo", ["bar", "bat"], "hoho")
     eq_regex(
         str(exception),
         r"\(.*.str\) hoho \[SQL: 'foo'\] \[parameters: \['bar', 'bat'\]\]")
Beispiel #4
0
    def test_boolean_roundtrip_reflected(self, boolean_table, store, expected):
        meta2 = MetaData(testing.db)
        table = Table("mysql_bool", meta2, autoload=True)
        eq_(colspec(table.c.b3), "b3 TINYINT(1)")
        eq_regex(colspec(table.c.b4), r"b4 TINYINT(?:\(1\))? UNSIGNED")

        meta2 = MetaData(testing.db)
        table = Table(
            "mysql_bool",
            meta2,
            Column("b1", BOOLEAN),
            Column("b2", Boolean),
            Column("b3", BOOLEAN),
            Column("b4", BOOLEAN),
            autoload=True,
        )
        eq_(colspec(table.c.b3), "b3 BOOL")
        eq_(colspec(table.c.b4), "b4 BOOL")

        with testing.db.connect() as conn:
            expected = expected or store
            conn.execute(table.insert(store))
            row = conn.execute(table.select()).first()
            eq_(list(row), expected)
            for i, val in enumerate(expected):
                if isinstance(val, bool):
                    self.assert_(val is row[i])
            conn.execute(table.delete())
Beispiel #5
0
    def test_year(self, metadata, connection):
        """Exercise YEAR."""

        year_table = Table(
            "mysql_year",
            metadata,
            Column("y1", mysql.MSYear),
            Column("y2", mysql.MSYear),
            Column("y3", mysql.MSYear),
            Column("y5", mysql.MSYear(4)),
        )

        for col in year_table.c:
            self.assert_(repr(col))
        year_table.create(connection)
        reflected = Table("mysql_year", MetaData(), autoload_with=connection)

        for table in year_table, reflected:
            connection.execute(
                table.insert().values(["1950", "50", None, 1950])
            )
            row = connection.execute(table.select()).first()
            eq_(list(row), [1950, 2050, None, 1950])
            self.assert_(colspec(table.c.y1).startswith("y1 YEAR"))
            eq_regex(colspec(table.c.y5), r"y5 YEAR(?:\(4\))?")
Beispiel #6
0
 def test_exception_format_unexpected_member_parameter(self):
     # test that if the parameters aren't any known type, we just
     # run through repr()
     exception = tsa.exc.IntegrityError("foo", ["bar", "bat"], "hoho")
     eq_regex(
         str(exception),
         r"\(.*.str\) hoho\n\[SQL: foo\]\n\[parameters: \['bar', 'bat'\]\]",
     )
Beispiel #7
0
 def test_exception_format_unexpected_parameter(self):
     # test that if the parameters aren't any known type, we just
     # run through repr()
     exception = tsa.exc.IntegrityError("foo", "bar", "bat")
     eq_regex(
         str(exception),
         r"\(.*.str\) bat \[SQL: 'foo'\] \[parameters: 'bar'\]"
     )
Beispiel #8
0
 def test_exception_format_unexpected_parameter(self):
     # test that if the parameters aren't any known type, we just
     # run through repr()
     exception = tsa.exc.IntegrityError("foo", "bar", "bat")
     eq_regex(
         str(exception),
         r"\(.*.str\) bat\n\[SQL: foo\]\n\[parameters: 'bar'\]",
     )
Beispiel #9
0
 def test_exception_format_hide_parameters(self):
     exception = tsa.exc.IntegrityError("foo", {"x": "y"},
                                        None,
                                        hide_parameters=True)
     eq_regex(
         str(exception),
         r"\(.*.NoneType\) None\n\[SQL: foo\]\n"
         r"\[SQL parameters hidden due to hide_parameters=True\]",
     )
Beispiel #10
0
    def test_log_positional_array(self):
        with self.eng.connect() as conn:
            exc_info = assert_raises(
                tsa.exc.DBAPIError,
                conn.execute,
                tsa.text("SELECT * FROM foo WHERE id IN :foo AND bar=:bar"),
                {"foo": [1, 2, 3], "bar": "hi"},
            )

            assert (
                "[SQL: SELECT * FROM foo WHERE id IN ? AND bar=?]\n"
                "[parameters: ([1, 2, 3], 'hi')]\n" in str(exc_info)
            )

            eq_regex(
                self.buf.buffer[1].message,
                r"\[generated .*\] \(\[1, 2, 3\], 'hi'\)",
            )
Beispiel #11
0
 def test_exception_format_dict_param(self):
     exception = tsa.exc.IntegrityError("foo", {"x": "y"}, None)
     eq_regex(
         str(exception),
         r"\(.*.NoneType\) None\n\[SQL: foo\]\n\[parameters: {'x': 'y'}\]",
     )
Beispiel #12
0
 def test_exception_format_dict_param(self):
     exception = tsa.exc.IntegrityError("foo", {"x": "y"}, None)
     eq_regex(
         str(exception),
         r"\(.*.NoneType\) None \[SQL: 'foo'\] \[parameters: {'x': 'y'}\]")
 def _assert_not_repr(self, cls, create, dc_arguments):
     a1 = create("some data", 12)
     eq_regex(repr(a1), r"<.*A object at 0x.*>")
 def _assert_repr(self, cls, create, dc_arguments):
     a1 = create("some data", 12)
     eq_regex(repr(a1), r".*A\(id=None, data='some data', x=12\)")