Index: trunk/tests/TestUtils.py =================================================================== diff -u -r87 -r148 --- trunk/tests/TestUtils.py (.../TestUtils.py) (revision 87) +++ trunk/tests/TestUtils.py (.../TestUtils.py) (revision 148) @@ -1,5 +1,7 @@ import sys import os +from pathlib import Path + try: from pip import main as pipmain except Exception: @@ -8,8 +10,9 @@ class TestUtils: - _name_external = 'external_test_data' - _name_local = 'test_data' + _name_external = "external_test_data" + _name_local = "test_data" + _name_output = "test_output" @staticmethod def install_package(package: str): @@ -19,16 +22,27 @@ Arguments: package {str} -- Name of the PIP package. """ - pipmain(['install', package]) + pipmain(["install", package]) @staticmethod + def get_output_test_data_dir(dir_name: str): + """ + Returns the full path of a directory containing generated + data from the tests. If it does not exist it creates it. + """ + directory = TestUtils.get_test_data_dir(dir_name, TestUtils._name_output) + if not directory.is_dir(): + # Create missing directories + Path.mkdir(directory, parents=True) + return directory + + @staticmethod def get_local_test_data_dir(dir_name: str): """ Returns the desired directory relative to the test data. Avoiding extra code on the tests. """ - directory = TestUtils.get_test_data_dir( - dir_name, TestUtils._name_local) + directory = TestUtils.get_test_data_dir(dir_name, TestUtils._name_local) return directory @staticmethod @@ -37,34 +51,27 @@ Returns the desired directory relative to the test external data. Avoiding extra code on the tests. """ - directory = TestUtils.get_test_data_dir( - dir_name, TestUtils._name_external) + directory = TestUtils.get_test_data_dir(dir_name, TestUtils._name_external) return directory @staticmethod - def get_test_data_dir(dir_name: str, test_data_name: str): + def get_test_data_dir(dir_name: str, test_data_name: str) -> Path: """ Returns the desired directory relative to the test external data. Avoiding extra code on the tests. """ - test_dir = os.path.dirname(__file__) - try: - dir_path = '{}\\{}\\'.format(test_data_name, dir_name) - test_dir = os.path.join(test_dir, dir_path) - except Exception: - print("An error occurred trying to find {}".format(dir_name)) - return test_dir + current_dir = Path(__file__).parent + return current_dir / test_data_name / dir_name @staticmethod - def get_test_dir(dir_name: str): + def get_test_dir(dir_name: str) -> Path: """Returns the desired directory inside the Tests folder Arguments: dir_name {str} -- Target directory. Returns: - {str} -- Path to the target directory. + {Path} -- Path to the target directory. """ - test_dir = os.path.dirname(__file__) - dir_path = os.path.join(test_dir, dir_name) - return dir_path + test_dir = Path(__file__).parent + return test_dir / dir_name