Skip to content

Commit

Permalink
Use ast.literal_eval instead of JSON parsing for stdout checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ethho committed Sep 12, 2024
1 parent 2b7b146 commit eb4ee23
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import json
import ast
import subprocess
import pytest
import datajoint as dj
Expand Down Expand Up @@ -60,21 +61,8 @@ def test_cli_config():
process.stdin.flush()

stdout, stderr = process.communicate()

snippet = stdout[4:519]
assert snippet
assert isinstance(snippet, str)
try:
assert dj.config == json.loads(
snippet.replace("'", '"')
.replace("None", "null")
.replace("True", "true")
.replace("False", "false")
)
except Exception as e:
print(snippet)
print(stdout)
raise AssertionError(f"Error decoding JSON {snippet=}") from e
cleaned = stdout.strip(" >\t\n\r")
assert dj.config == ast.literal_eval(cleaned)


def test_cli_args():
Expand Down

0 comments on commit eb4ee23

Please sign in to comment.