From aef3ac601e1596d5c370e886beb649c937a8ed8b Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:01:18 +0100 Subject: [PATCH 1/7] Add mock to test_requirements.txt Fix #103 --- tests/test_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_requirements.txt b/tests/test_requirements.txt index b7cafaa6e..f13402b63 100644 --- a/tests/test_requirements.txt +++ b/tests/test_requirements.txt @@ -5,3 +5,4 @@ graphviz==0.13 sphinx==2.2.2 coverage==4.5 python-coveralls==2.9.3 +mock==3.0.5 From b37834355e4ea16d14b6da15a8e7bb643bfa1e65 Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:02:40 +0100 Subject: [PATCH 2/7] Test a normal execution of the program Mock patch is used to mock command line arguments --- tests/test_simulation.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 648b4058e..6b982a9fd 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -1,9 +1,24 @@ -import pytest import os +import mock +import argparse +import shutil from mvs_eland_tool.mvs_eland_tool import main +OUTPUT_PATH = os.path.join(".", "tests", "MVS_outputs_simulation") -def test_run_smoothly(): - # Ensure that code does not terminate + +def setup_module(): + if os.path.exists(OUTPUT_PATH): + shutil.rmtree(OUTPUT_PATH, ignore_errors=True) + + +@mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace()) +def test_run_smoothly(mock_args): + + main(path_output_folder=OUTPUT_PATH) assert 1 == 1 + + +def teardown_module(): + shutil.rmtree(OUTPUT_PATH, ignore_errors=True) From 6fbcba34a52e78441e44786e4c256cf889bbfd8d Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:06:50 +0100 Subject: [PATCH 3/7] Create file in root of repo for easier access to mvs tool --- mvs_tool.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 mvs_tool.py diff --git a/mvs_tool.py b/mvs_tool.py new file mode 100644 index 000000000..45abec2b9 --- /dev/null +++ b/mvs_tool.py @@ -0,0 +1,4 @@ +from mvs_eland_tool.mvs_eland_tool import main + +if __name__ == "__main__": + main() \ No newline at end of file From 68544e1c4dc51b762c15f2e6f80f8a0afea82af1 Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:07:04 +0100 Subject: [PATCH 4/7] Update readme instruction to get started --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6e3250159..2b0899cf4 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ To set up the MVS, follow the steps below: * Test if the MVS is running by executing - `python mvs_eland_tool/mvs_eland_tool.py` + `python mvs_tool.py` * You can also run all existing tests by executing @@ -90,7 +90,7 @@ To set up the MVS, follow the steps below: To run the MVS with custom inputs, edit the json input file and run - `python mvs_eland_tool/mvs_eland_tool.py -i path_input_file -o path_output_folder` + `python mvs_tool.py -i path_input_file -o path_output_folder` With `path_input_file`: path to json input file @@ -98,7 +98,7 @@ and `path_output_folder`: path of the folder where simulation results should be For more information about the possible command lines -`python mvs_eland_tool/mvs_eland_tool.py -h` +`python mvs_tool.py -h` ## Contributing From 7a109e898aa1591c22eed3ba598565895c92871c Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:19:13 +0100 Subject: [PATCH 5/7] Disable the test simulation by default One has to especially run `pytest tests/test_simulation.py` --- mvs_tool.py | 2 +- tests/test_simulation.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mvs_tool.py b/mvs_tool.py index 45abec2b9..45ff821a7 100644 --- a/mvs_tool.py +++ b/mvs_tool.py @@ -1,4 +1,4 @@ from mvs_eland_tool.mvs_eland_tool import main if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 6b982a9fd..61f4df06a 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -1,7 +1,9 @@ import os -import mock +import sys import argparse import shutil +import mock +import pytest from mvs_eland_tool.mvs_eland_tool import main @@ -13,9 +15,13 @@ def setup_module(): shutil.rmtree(OUTPUT_PATH, ignore_errors=True) +# this ensure that the test is only ran if explicitly executed, ie not when the `pytest` command +# alone it called +@pytest.mark.skipif( + "tests/test_simulation.py" not in sys.argv, reason="requires python3.3" +) @mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace()) def test_run_smoothly(mock_args): - main(path_output_folder=OUTPUT_PATH) assert 1 == 1 From 706b866b49357acd97225206e512da037ca59edd Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:19:26 +0100 Subject: [PATCH 6/7] Fix the test Fix #108 --- mvs_eland_tool/mvs_eland_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvs_eland_tool/mvs_eland_tool.py b/mvs_eland_tool/mvs_eland_tool.py index b0b6725eb..096c9dbad 100644 --- a/mvs_eland_tool/mvs_eland_tool.py +++ b/mvs_eland_tool/mvs_eland_tool.py @@ -72,7 +72,7 @@ def main(**kwargs): # # todo: is user input completely used? # dict_values = data_input.load_json(user_input["path_input_file"]) - if not kwargs["path_input_file"].endswith("json"): + if not user_input["path_input_file"].endswith("json"): logging.debug("Accessing script: A1_csv_to_json") path_to_json_from_csv = load_data_from_csv.create_input_json() user_input.update({"path_input_file": path_to_json_from_csv}) From 390701b325a40900c6ca37c9de8bb5b1d9ce6ac2 Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Thu, 30 Jan 2020 15:31:06 +0100 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d333151ea..2b39266cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,10 +20,10 @@ Here is a template for new release sections ## [Unreleased] ### Added - -### Changed - -### Removed +- test for running the main function (#109) +- the user can run the tool simply with `python mvs_tool.py` (#109) +### Fixed +- \#108 (#109)