Skip to content

Commit ede2f31

Browse files
committed
Remove duplicate assertSql in smoke test
1 parent 8307d7c commit ede2f31

File tree

6 files changed

+19
-39
lines changed

6 files changed

+19
-39
lines changed

smoketests/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,14 @@ def enterClassContext(cls, cm):
407407
result = cm.__enter__()
408408
cls.addClassCleanup(cm.__exit__, None, None, None)
409409
return result
410-
410+
411+
def assertSql(self, sql: str, expected: str):
412+
"""Assert that executing `sql` produces the expected output."""
413+
self.maxDiff = None
414+
sql_out = self.spacetime("sql", self.database_identity, sql)
415+
sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()])
416+
expected = "\n".join([line.rstrip() for line in expected.splitlines()])
417+
self.assertMultiLineEqual(sql_out, expected)
411418

412419
# This is a custom thread class that will propagate an exception to the caller of `.join()`.
413420
# This is required because, by default, threads do not propagate exceptions to their callers,

smoketests/tests/auto_migration.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ class AddTableAutoMigration(Smoketest):
106106
"""
107107
)
108108

109-
def assertSql(self, sql, expected):
110-
self.maxDiff = None
111-
sql_out = self.spacetime("sql", self.database_identity, sql)
112-
sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()])
113-
expected = "\n".join([line.rstrip() for line in expected.splitlines()])
114-
self.assertMultiLineEqual(sql_out, expected)
115-
116109
def test_add_table_auto_migration(self):
117110
"""This tests uploading a module with a schema change that should not require clearing the database."""
118111

smoketests/tests/pg_wire.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def connect_db(self, identity: str):
167167
conn.set_session(autocommit=True) # Disable automic transaction
168168
return conn
169169

170-
def assertSql(self, token: str, sql: str, expected):
170+
def assertPsql(self, token: str, sql: str, expected):
171+
"""Assert that the output of `psql` matches the expected output."""
171172
self.maxDiff = None
172173
sql_out = self.psql(token, sql)
173174
sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()])
@@ -188,48 +189,48 @@ def test_sql_format(self):
188189

189190
self.call("test")
190191

191-
self.assertSql(token, "SELECT * FROM t_ints", """\
192+
self.assertPsql(token, "SELECT * FROM t_ints", """\
192193
i8 | i16 | i32 | i64 | i128 | i256
193194
-----+-------+--------+----------+---------------+---------------
194195
-25 | -3224 | -23443 | -2344353 | -234434897853 | -234434897853
195196
(1 row)""")
196-
self.assertSql(token, "SELECT * FROM t_ints_tuple", """\
197+
self.assertPsql(token, "SELECT * FROM t_ints_tuple", """\
197198
tuple
198199
---------------------------------------------------------------------------------------------------------
199200
{"i8": -25, "i16": -3224, "i32": -23443, "i64": -2344353, "i128": -234434897853, "i256": -234434897853}
200201
(1 row)""")
201-
self.assertSql(token, "SELECT * FROM t_uints", """\
202+
self.assertPsql(token, "SELECT * FROM t_uints", """\
202203
u8 | u16 | u32 | u64 | u128 | u256
203204
-----+------+-------+----------+---------------+---------------
204205
105 | 1050 | 83892 | 48937498 | 4378528978889 | 4378528978889
205206
(1 row)""")
206-
self.assertSql(token, "SELECT * FROM t_uints_tuple", """\
207+
self.assertPsql(token, "SELECT * FROM t_uints_tuple", """\
207208
tuple
208209
-------------------------------------------------------------------------------------------------------
209210
{"u8": 105, "u16": 1050, "u32": 83892, "u64": 48937498, "u128": 4378528978889, "u256": 4378528978889}
210211
(1 row)""")
211-
self.assertSql(token, "SELECT * FROM t_others", """\
212+
self.assertPsql(token, "SELECT * FROM t_others", """\
212213
bool | f32 | f64 | str | bytes | identity | connection_id | timestamp | duration
213214
------+-----------+---------------------+---------------------+------------------+--------------------------------------------------------------------+------------------------------------+---------------------------+----------
214215
t | 594806.56 | -3454353.3453890434 | This is spacetimedb | \\x01020304050607 | \\x0000000000000000000000000000000000000000000000000000000000000001 | \\x00000000000000000000000000000000 | 1970-01-01T00:00:00+00:00 | PT10S
215216
(1 row)""")
216-
self.assertSql(token, "SELECT * FROM t_others_tuple", """\
217+
self.assertPsql(token, "SELECT * FROM t_others_tuple", """\
217218
tuple
218219
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
219220
{"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"}
220221
(1 row)""")
221-
self.assertSql(token, "SELECT * FROM t_simple_enum", """\
222+
self.assertPsql(token, "SELECT * FROM t_simple_enum", """\
222223
id | action
223224
----+----------
224225
1 | Inactive
225226
2 | Active
226227
(2 rows)""")
227-
self.assertSql(token, "SELECT * FROM t_enum", """\
228+
self.assertPsql(token, "SELECT * FROM t_enum", """\
228229
id | color
229230
----+---------------
230231
1 | {"Gray": 128}
231232
(1 row)""")
232-
self.assertSql(token, "SELECT * FROM t_nested", """\
233+
self.assertPsql(token, "SELECT * FROM t_nested", """\
233234
en | se | ints
234235
-----------------------------------+-------------------------------------+---------------------------------------------------------------------------------------------------------
235236
{"id": 1, "color": {"Gray": 128}} | {"id": 2, "action": {"Active": {}}} | {"i8": -25, "i16": -3224, "i32": -23443, "i64": -2344353, "i128": -234434897853, "i256": -234434897853}

smoketests/tests/rls.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ class Rls(Smoketest):
2121
}
2222
"""
2323

24-
def assertSql(self, sql, expected):
25-
self.maxDiff = None
26-
sql_out = self.spacetime("sql", self.database_identity, sql)
27-
sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()])
28-
expected = "\n".join([line.rstrip() for line in expected.splitlines()])
29-
self.assertMultiLineEqual(sql_out, expected)
30-
3124
def test_rls_rules(self):
3225
"""Tests for querying tables with RLS rules"""
3326

smoketests/tests/sql.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@ class SqlFormat(Smoketest):
9797
}
9898
"""
9999

100-
def assertSql(self, sql, expected):
101-
self.maxDiff = None
102-
sql_out = self.spacetime("sql", self.database_identity, sql)
103-
sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()])
104-
expected = "\n".join([line.rstrip() for line in expected.splitlines()])
105-
self.assertMultiLineEqual(sql_out, expected)
106-
107100
def test_sql_format(self):
108101
"""This test is designed to test the format of the output of sql queries"""
109102

smoketests/tests/views.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ class Views(Smoketest):
2020
}
2121
"""
2222

23-
def assertSql(self, sql, expected):
24-
self.maxDiff = None
25-
sql_out = self.spacetime("sql", self.database_identity, sql)
26-
sql_out = "\n".join([line.rstrip() for line in sql_out.splitlines()])
27-
expected = "\n".join([line.rstrip() for line in expected.splitlines()])
28-
self.assertMultiLineEqual(sql_out, expected)
29-
3023
def test_st_view_tables(self):
3124
"""This test asserts that views populate the st_view_* system tables"""
3225

0 commit comments

Comments
 (0)