From 4fd697dbe7f1aa5b386f12cd8ca4973762270f8c Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Wed, 16 Aug 2023 13:50:00 +0200 Subject: [PATCH] feat: bootstrap scripts to manage test data files --- README.md | 22 ++++++++++++++++++++++ scripts/find_tc_using_test_data.py | 20 ++++++++++++++++++++ scripts/find_unused_test_data.py | 23 +++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 scripts/find_tc_using_test_data.py create mode 100644 scripts/find_unused_test_data.py diff --git a/README.md b/README.md index dd954b72..7f81c6c3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ specification of the ETSI NGSI-LD API. - [Install IDE (PyCharm)](#install-ide-pycharm) - [Run configurations (PyCharm)](#run-configurations-pycharm) - [Pre commit](#pre-commit) +- [Tooling](#tooling) - [Frameworks and libraries used in the project](#frameworks-and-libraries-used-in-the-project) - [Useful links](#useful-links) - [LICENSE](#license) @@ -185,6 +186,27 @@ To manually launch the tool, the following command can be used: Further details can be found on the [pre-commit](https://pre-commit.com) site. +## Tooling + +### Find unused test data files + +The `find_unused_test_data.py` script in the `scripts` directory can be used to get a list of the test data files +that are not used by any Test Case: + +``` +python3 scripts/find_unused_test_data.py +``` + +### Find and run Test Cases using a given test data file + +The `find_tc_using_test_data.py` script in the `scripts` directory can be used to find the Test Cases that are using a +given test data file. It can optionally run all the matching Test Cases: + +``` +python3 scripts/find_tc_using_test_data.py +``` + +When launched, the script asks for a test date file name and if the matching Test Cases should be executed. ## Frameworks and libraries used in the project diff --git a/scripts/find_tc_using_test_data.py b/scripts/find_tc_using_test_data.py new file mode 100644 index 00000000..f2f67221 --- /dev/null +++ b/scripts/find_tc_using_test_data.py @@ -0,0 +1,20 @@ +import os +import robot + + +def find_test_data_in_tc(dir, filename, run_matching_tc): + for file in os.listdir(dir): + path = dir + "/" + file + if os.path.isdir(path): + find_test_data_in_tc(path, filename, run_matching_tc) + else: + if filename in open(path).read(): + if run_matching_tc == "Y": + robot.run(path) + print(path) + + +if __name__ == '__main__': + test_data_file = input("Name of test data file to search for: ") + run_matching_tc = input("Run matching Test Cases (Y/N)?: ") + find_test_data_in_tc("TP", test_data_file, run_matching_tc) diff --git a/scripts/find_unused_test_data.py b/scripts/find_unused_test_data.py new file mode 100644 index 00000000..6a961e79 --- /dev/null +++ b/scripts/find_unused_test_data.py @@ -0,0 +1,23 @@ +import os + + +def list_files_in_dir(dirname): + for fname in os.listdir(dirname): + if os.path.isfile(dirname + "/" + fname): + print("Looking at test data file: ", fname) + find_test_data_in_tc("TP", fname) + else: + list_files_in_dir(dirname + "/" + fname) + + +def find_test_data_in_tc(dir, filename): + for file in os.listdir(dir): + path = dir + "/" + file + if os.path.isdir(path): + find_test_data_in_tc(path, filename) + else: + if filename in open(path).read(): + print("Found usage of", filename, "in", path) + + +list_files_in_dir("data") -- GitLab