Mercurial > p > roundup > code
diff test/test_anypy.py @ 7766:c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
strings.py:
When reading csv export files, use the safer literal_eval to
evaluate the fields. Issue pointed out by ruff linter.
Other Cleanup:
sort imports
replace if, else, if, else with if, elif, else
use isinstance with tuples rather than 'isinstance() or
isinstance()'
test_anypy.py:
Added tests for tuples, and booleans. Also added exception handling
for malformed strings, booleans, tuples.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 02 Mar 2024 04:01:22 -0500 |
| parents | e4db9d0b85c7 |
| children | ebb03b8cee4d |
line wrap: on
line diff
--- a/test/test_anypy.py Sat Mar 02 02:30:12 2024 -0500 +++ b/test/test_anypy.py Sat Mar 02 04:01:22 2024 -0500 @@ -17,6 +17,23 @@ val = eval_import("('issue', 2345L, 'status')") self.assertSequenceEqual(val, ('issue', 2345, 'status')) + # eval a tuple e.g. date representation + val = eval_import("(2022, 9, 6, 3, 58, 4.776, 0, 0, 0)") + self.assertSequenceEqual(val, (2022, 9, 6, 3, 58, 4.776, 0, 0, 0)) + + # eval a boolean + val = eval_import("False") + self.assertEqual(val, False) + val = eval_import("True") + self.assertEqual(val, True) + + # check syntax error + for testcase in ['true', '(2004, 10, 20', "2000, 10, 22)", + "test'", '"test']: + with self.assertRaises(ValueError) as m: + val = eval_import(testcase) + print(m.exception) + # python3 export with id as number val = eval_import("('issue', 2345, 'status')") self.assertSequenceEqual(val, ('issue', 2345, 'status'))
