diff --git a/README.md b/README.md index dd954b729c2d48a270a8b33b61d5c57386949b32..7f81c6c3a62e3022d2b9e53ebab814d72c84d2bb 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 0000000000000000000000000000000000000000..f2f67221248cf3d0a33ed3837aa08bb11f5d8e00 --- /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 0000000000000000000000000000000000000000..6a961e797ebb2aa38ec2df15d81347786f53e604 --- /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")