From 0275b1929662649d9949783fc50f5282afb7c25e Mon Sep 17 00:00:00 2001 From: Taekyung Heo <7621438+TaekyungHeo@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:25:14 -0500 Subject: [PATCH] Add test_et_jsonizer.py --- tests/test_et_jsonizer.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_et_jsonizer.py diff --git a/tests/test_et_jsonizer.py b/tests/test_et_jsonizer.py new file mode 100644 index 00000000..9b240466 --- /dev/null +++ b/tests/test_et_jsonizer.py @@ -0,0 +1,21 @@ +import pytest +from chakra.et_jsonizer import main +from unittest.mock import patch, mock_open + +def test_run_with_valid_input(): + test_args = ["et_jsonizer.py", "--input_filename", "valid_input.et", "--output_filename", "output.json"] + with patch('sys.argv', test_args), \ + patch('chakra.et_jsonizer.open_file_rd') as mock_open_file_rd, \ + patch('builtins.open', mock_open()): + main() # No assertion needed; we're checking if it runs without error + +def test_missing_arguments(): + with pytest.raises(SystemExit): + with patch('sys.argv', ['et_jsonizer.py']): + main() + +def test_missing_file_path(): + test_args = ["et_jsonizer.py", "--input_filename", "nonexistent_input.et", "--output_filename", "output.json"] + with patch('sys.argv', test_args): + with pytest.raises(FileNotFoundError): + main()