diff --git a/smoketests/__init__.py b/smoketests/__init__.py index 24e6f46f4e4..69c45e1b4a5 100644 --- a/smoketests/__init__.py +++ b/smoketests/__init__.py @@ -407,7 +407,14 @@ def enterClassContext(cls, cm): result = cm.__enter__() cls.addClassCleanup(cm.__exit__, None, None, None) return result - + + def assertSql(self, sql: str, expected: str): + """Assert that executing `sql` produces the expected output.""" + self.maxDiff = None + sql_out = self.spacetime("sql", self.database_identity, sql) + sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()]) + expected = "\n".join([line.rstrip() for line in expected.splitlines()]) + self.assertMultiLineEqual(sql_out, expected) # This is a custom thread class that will propagate an exception to the caller of `.join()`. # This is required because, by default, threads do not propagate exceptions to their callers, diff --git a/smoketests/tests/auto_migration.py b/smoketests/tests/auto_migration.py index fb02d3e4dab..6f89113fbd2 100644 --- a/smoketests/tests/auto_migration.py +++ b/smoketests/tests/auto_migration.py @@ -106,13 +106,6 @@ class AddTableAutoMigration(Smoketest): """ ) - def assertSql(self, sql, expected): - self.maxDiff = None - sql_out = self.spacetime("sql", self.database_identity, sql) - sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()]) - expected = "\n".join([line.rstrip() for line in expected.splitlines()]) - self.assertMultiLineEqual(sql_out, expected) - def test_add_table_auto_migration(self): """This tests uploading a module with a schema change that should not require clearing the database.""" diff --git a/smoketests/tests/pg_wire.py b/smoketests/tests/pg_wire.py index 24402e2ec9f..3e86d619473 100644 --- a/smoketests/tests/pg_wire.py +++ b/smoketests/tests/pg_wire.py @@ -167,7 +167,8 @@ def connect_db(self, identity: str): conn.set_session(autocommit=True) # Disable automic transaction return conn - def assertSql(self, token: str, sql: str, expected): + def assertPsql(self, token: str, sql: str, expected): + """Assert that the output of `psql` matches the expected output.""" self.maxDiff = None sql_out = self.psql(token, sql) sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()]) @@ -188,48 +189,48 @@ def test_sql_format(self): self.call("test") - self.assertSql(token, "SELECT * FROM t_ints", """\ + self.assertPsql(token, "SELECT * FROM t_ints", """\ i8 | i16 | i32 | i64 | i128 | i256 -----+-------+--------+----------+---------------+--------------- -25 | -3224 | -23443 | -2344353 | -234434897853 | -234434897853 (1 row)""") - self.assertSql(token, "SELECT * FROM t_ints_tuple", """\ + self.assertPsql(token, "SELECT * FROM t_ints_tuple", """\ tuple --------------------------------------------------------------------------------------------------------- {"i8": -25, "i16": -3224, "i32": -23443, "i64": -2344353, "i128": -234434897853, "i256": -234434897853} (1 row)""") - self.assertSql(token, "SELECT * FROM t_uints", """\ + self.assertPsql(token, "SELECT * FROM t_uints", """\ u8 | u16 | u32 | u64 | u128 | u256 -----+------+-------+----------+---------------+--------------- 105 | 1050 | 83892 | 48937498 | 4378528978889 | 4378528978889 (1 row)""") - self.assertSql(token, "SELECT * FROM t_uints_tuple", """\ + self.assertPsql(token, "SELECT * FROM t_uints_tuple", """\ tuple ------------------------------------------------------------------------------------------------------- {"u8": 105, "u16": 1050, "u32": 83892, "u64": 48937498, "u128": 4378528978889, "u256": 4378528978889} (1 row)""") - self.assertSql(token, "SELECT * FROM t_others", """\ + self.assertPsql(token, "SELECT * FROM t_others", """\ bool | f32 | f64 | str | bytes | identity | connection_id | timestamp | duration ------+-----------+---------------------+---------------------+------------------+--------------------------------------------------------------------+------------------------------------+---------------------------+---------- t | 594806.56 | -3454353.3453890434 | This is spacetimedb | \\x01020304050607 | \\x0000000000000000000000000000000000000000000000000000000000000001 | \\x00000000000000000000000000000000 | 1970-01-01T00:00:00+00:00 | PT10S (1 row)""") - self.assertSql(token, "SELECT * FROM t_others_tuple", """\ + self.assertPsql(token, "SELECT * FROM t_others_tuple", """\ tuple --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {"bool": true, "f32": 594806.56, "f64": -3454353.3453890434, "str": "This is spacetimedb", "bytes": "0x01020304050607", "identity": "0x0000000000000000000000000000000000000000000000000000000000000001", "connection_id": "0x00000000000000000000000000000000", "timestamp": "1970-01-01T00:00:00+00:00", "duration": "PT10S"} (1 row)""") - self.assertSql(token, "SELECT * FROM t_simple_enum", """\ + self.assertPsql(token, "SELECT * FROM t_simple_enum", """\ id | action ----+---------- 1 | Inactive 2 | Active (2 rows)""") - self.assertSql(token, "SELECT * FROM t_enum", """\ + self.assertPsql(token, "SELECT * FROM t_enum", """\ id | color ----+--------------- 1 | {"Gray": 128} (1 row)""") - self.assertSql(token, "SELECT * FROM t_nested", """\ + self.assertPsql(token, "SELECT * FROM t_nested", """\ en | se | ints -----------------------------------+-------------------------------------+--------------------------------------------------------------------------------------------------------- {"id": 1, "color": {"Gray": 128}} | {"id": 2, "action": {"Active": {}}} | {"i8": -25, "i16": -3224, "i32": -23443, "i64": -2344353, "i128": -234434897853, "i256": -234434897853} diff --git a/smoketests/tests/rls.py b/smoketests/tests/rls.py index 04bcc5c2804..57cc9eda90d 100644 --- a/smoketests/tests/rls.py +++ b/smoketests/tests/rls.py @@ -21,13 +21,6 @@ class Rls(Smoketest): } """ - def assertSql(self, sql, expected): - self.maxDiff = None - sql_out = self.spacetime("sql", self.database_identity, sql) - sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()]) - expected = "\n".join([line.rstrip() for line in expected.splitlines()]) - self.assertMultiLineEqual(sql_out, expected) - def test_rls_rules(self): """Tests for querying tables with RLS rules""" diff --git a/smoketests/tests/sql.py b/smoketests/tests/sql.py index c90d63c3661..6ea5082ebe6 100644 --- a/smoketests/tests/sql.py +++ b/smoketests/tests/sql.py @@ -97,13 +97,6 @@ class SqlFormat(Smoketest): } """ - def assertSql(self, sql, expected): - self.maxDiff = None - sql_out = self.spacetime("sql", self.database_identity, sql) - sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()]) - expected = "\n".join([line.rstrip() for line in expected.splitlines()]) - self.assertMultiLineEqual(sql_out, expected) - def test_sql_format(self): """This test is designed to test the format of the output of sql queries""" diff --git a/smoketests/tests/views.py b/smoketests/tests/views.py index 49e97f27906..937800ff182 100644 --- a/smoketests/tests/views.py +++ b/smoketests/tests/views.py @@ -20,13 +20,6 @@ class Views(Smoketest): } """ - def assertSql(self, sql, expected): - self.maxDiff = None - sql_out = self.spacetime("sql", self.database_identity, sql) - sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()]) - expected = "\n".join([line.rstrip() for line in expected.splitlines()]) - self.assertMultiLineEqual(sql_out, expected) - def test_st_view_tables(self): """This test asserts that views populate the st_view_* system tables"""