Skip to content

Commit

Permalink
Swapped the order of a bunch of pytest comparisons
Browse files Browse the repository at this point in the history
When I wrote this I thought constant == value was a better assertion. I no longer think that.
  • Loading branch information
simonw committed Aug 18, 2023
1 parent b4735f7 commit d2bcdc0
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 82 deletions.
18 changes: 9 additions & 9 deletions tests/test_cli.py
Expand Up @@ -237,7 +237,7 @@ def test_create_index(db_path):
)
] == db["Gosh2"].indexes
# Trying to create the same index should fail
assert 0 != CliRunner().invoke(cli.cli, create_index_unique_args).exit_code
assert CliRunner().invoke(cli.cli, create_index_unique_args).exit_code != 0
# ... unless we use --if-not-exists or --ignore
for option in ("--if-not-exists", "--ignore"):
assert (
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_add_foreign_key(db_path, args, assert_message):
]
)
assert (
0 == CliRunner().invoke(cli.cli, ["add-foreign-key", db_path] + args).exit_code
CliRunner().invoke(cli.cli, ["add-foreign-key", db_path] + args).exit_code == 0
), assert_message
assert [
ForeignKey(
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def test_upsert_alter(db_path, tmpdir):
result = CliRunner().invoke(
cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id"]
)
assert 1 == result.exit_code
assert result.exit_code == 1
assert (
"Error: no such column: age\n\n"
"sql = UPDATE [dogs] SET [age] = ? WHERE [id] = ?\n"
Expand All @@ -1116,9 +1116,9 @@ def test_upsert_alter(db_path, tmpdir):
cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id", "--alter"]
)
assert result.exit_code == 0
assert [
assert list(db.query("select * from dogs order by id")) == [
{"id": 1, "name": "Cleo", "age": 5},
] == list(db.query("select * from dogs order by id"))
]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1240,7 +1240,7 @@ def test_create_table_error_if_table_exists():
result = runner.invoke(
cli.cli, ["create-table", "test.db", "dogs", "id", "integer"]
)
assert 1 == result.exit_code
assert result.exit_code == 1
assert (
'Error: Table "dogs" already exists. Use --replace to delete and replace it.'
== result.output.strip()
Expand Down Expand Up @@ -1290,7 +1290,7 @@ def test_create_view_error_if_view_exists():
result = runner.invoke(
cli.cli, ["create-view", "test.db", "version", "select sqlite_version()"]
)
assert 1 == result.exit_code
assert result.exit_code == 1
assert (
'Error: View "version" already exists. Use --replace to delete and replace it.'
== result.output.strip()
Expand Down Expand Up @@ -1368,7 +1368,7 @@ def test_drop_table_error():
"t2",
],
)
assert 1 == result.exit_code
assert result.exit_code == 1
assert 'Error: Table "t2" does not exist' == result.output.strip()
# Using --ignore suppresses that error
result = runner.invoke(
Expand Down Expand Up @@ -1409,7 +1409,7 @@ def test_drop_view_error():
"t2",
],
)
assert 1 == result.exit_code
assert result.exit_code == 1
assert 'Error: View "t2" does not exist' == result.output.strip()
# Using --ignore suppresses that error
result = runner.invoke(
Expand Down
28 changes: 14 additions & 14 deletions tests/test_cli_convert.py
Expand Up @@ -49,7 +49,7 @@ def test_convert_code(fresh_db_and_path, code):
result = CliRunner().invoke(
cli.cli, ["convert", db_path, "t", "text", code], catch_exceptions=False
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
value = list(db["t"].rows)[0]["text"]
assert value == "Spooktober"

Expand All @@ -67,7 +67,7 @@ def test_convert_code_errors(fresh_db_and_path, bad_code):
result = CliRunner().invoke(
cli.cli, ["convert", db_path, "t", "text", bad_code], catch_exceptions=False
)
assert 1 == result.exit_code
assert result.exit_code == 1
assert result.output == "Error: Could not compile code\n"


Expand All @@ -85,7 +85,7 @@ def test_convert_import(test_db_and_path):
"re",
],
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert [
{"id": 1, "dt": "5th OXXober 2019 12:04"},
{"id": 2, "dt": "6th OXXober 2019 00:05:06"},
Expand All @@ -109,7 +109,7 @@ def test_convert_import_nested(fresh_db_and_path):
"xml.etree.ElementTree",
],
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert [
{"xml": "Cleo"},
] == list(db["example"].rows)
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_convert_output_column(test_db_and_path, drop):
if drop:
args += ["--drop"]
result = CliRunner().invoke(cli.cli, args)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
expected = [
{
"id": 1,
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_convert_output_column_output_type(test_db_and_path, output_type, expect
cli.cli,
args,
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert expected == list(db.execute("select id, new_id from example"))


Expand Down Expand Up @@ -428,7 +428,7 @@ def test_recipe_jsonsplit(tmpdir, delimiter):
code = 'recipes.jsonsplit(value, delimiter="{}")'.format(delimiter)
args = ["convert", db_path, "example", "tags", code]
result = CliRunner().invoke(cli.cli, args)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert list(db["example"].rows) == [
{"id": 1, "tags": '["foo", "bar"]'},
{"id": 2, "tags": '["bar", "baz"]'},
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_recipe_jsonsplit_type(fresh_db_and_path, type, expected_array):
code = "recipes.jsonsplit(value, type={})".format(type)
args = ["convert", db_path, "example", "records", code]
result = CliRunner().invoke(cli.cli, args)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert json.loads(db["example"].get(1)["records"]) == expected_array


Expand All @@ -474,7 +474,7 @@ def test_recipe_jsonsplit_output(fresh_db_and_path, drop):
if drop:
args += ["--drop"]
result = CliRunner().invoke(cli.cli, args)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
expected = {
"id": 1,
"records": "1,2,3",
Expand Down Expand Up @@ -568,7 +568,7 @@ def test_convert_where_multi(fresh_db_and_path):
"--multi",
],
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert list(db["names"].rows) == [
{"id": 1, "name": "Cleo", "upper": None},
{"id": 2, "name": "Bants", "upper": "BANTS"},
Expand All @@ -589,7 +589,7 @@ def test_convert_code_standard_input(fresh_db_and_path):
],
input="value.upper()",
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert list(db["names"].rows) == [
{"id": 1, "name": "CLEO"},
]
Expand All @@ -602,7 +602,7 @@ def test_convert_hyphen_workaround(fresh_db_and_path):
cli.cli,
["convert", db_path, "names", "name", '"-"'],
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert list(db["names"].rows) == [
{"id": 1, "name": "-"},
]
Expand All @@ -622,7 +622,7 @@ def test_convert_initialization_pattern(fresh_db_and_path):
],
input="import random\nrandom.seed(1)\ndef convert(value): return random.randint(0, 100)",
)
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert list(db["names"].rows) == [
{"id": 1, "name": "17"},
]
Expand Down Expand Up @@ -650,6 +650,6 @@ def test_convert_no_skip_false(fresh_db_and_path, no_skip_false, expected):
assert db["t"].get(1)["x"] == 0
assert db["t"].get(2)["x"] == 1
result = CliRunner().invoke(cli.cli, args, input="value + 1")
assert 0 == result.exit_code, result.output
assert result.exit_code == 0, result.output
assert db["t"].get(1)["x"] == expected
assert db["t"].get(2)["x"] == 2

0 comments on commit d2bcdc0

Please sign in to comment.