diff --git a/komodo/matrix.py b/komodo/matrix.py index 4db47ad9..df6ff2e2 100644 --- a/komodo/matrix.py +++ b/komodo/matrix.py @@ -14,7 +14,7 @@ def get_matrix( current release matrix.""" for product in itertools.product(rhel_versions, py_versions): rh_ver, py_ver = product - yield (f"rhel{rh_ver}", f"py{py_ver.replace('.', '')}") + yield (f"rhel{rh_ver}", f"py{str(py_ver).replace('.', '')}") def format_release(base: str, rhel_ver: str, py_ver: str) -> str: diff --git a/komodo/release_transpiler.py b/komodo/release_transpiler.py index fad7b015..4b93bf3b 100755 --- a/komodo/release_transpiler.py +++ b/komodo/release_transpiler.py @@ -217,24 +217,23 @@ def main(): def checkValidPythonVersion(input: str) -> list: output_list = [] - for item in input.split(','): - if (re.match(r"^[2,3](\.\d+)?$", item) == None): + for item in input.split(","): + if re.match(r"^[2,3](\.\d+)?$", item) == None: raise TypeError(item) else: output_list.append(item) return output_list + matrix_parser.add_argument( "--py_coords", help="""Comma delimitated list of python versions to be combined, for example, "3.6,3.8" (without spaces). If None, the release files in release-folder will be used to imply the versions to combine.""", - type=checkValidPythonVersion, #lambda s: [x for x in s.split(',') if (re.match(r"^[2,3](\.\d+)?$", x) != None)], #re.split(",", s), + type=checkValidPythonVersion, # lambda s: [x for x in s.split(',') if (re.match(r"^[2,3](\.\d+)?$", x) != None)], #re.split(",", s), required=False, default=None, ) - - transpile_parser = subparsers.add_parser( "transpile", @@ -266,14 +265,14 @@ def checkValidPythonVersion(input: str) -> list: def check_if_valid_file(path: str) -> str: - if (os.path.isfile(path)): + if os.path.isfile(path): return path raise TypeError(path) def dir_path(should_be_valid_path: str) -> str: if os.path.isdir(should_be_valid_path): - return should_be_valid_path + return should_be_valid_path raise TypeError(should_be_valid_path) diff --git a/tests/test_release_transpiler_argument_types.py b/tests/test_release_transpiler_argument_types.py new file mode 100644 index 00000000..caf16676 --- /dev/null +++ b/tests/test_release_transpiler_argument_types.py @@ -0,0 +1,224 @@ +import os +from os.path import abspath, dirname + +import pytest + +RELEASE_TRANSPILER_FILE_PATH = abspath( + dirname(dirname(abspath(__file__))) + "/komodo/release_transpiler.py" +) +VALID_RELEASE_FOLDER = abspath(dirname(__file__) + "/data/test_releases") +VALID_RELEASE_BASE = "2020.01.a1" +VALID_OVERRIDE_MAPPING_FILE = abspath( + dirname(dirname(__file__)) + "/examples/stable.yml" +) # "/Users/JONAK/Documents/FMU/SCOUT/komodo/examples/stable.yml" +VALID_PYTHON_COORDS = "3.6,3.8" + + +# TESTING COMBINER +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords 3.8,3.6", + 0, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 0, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords py3.8", + 512, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords test", + 512, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords 3.8, 3.6", + 512, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords true", + 512, + ), + ], +) +def test_combine_py_coords_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} combine {args}") + assert exit_code == expectedExitCode + + +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords 3.8,3.6", + 0, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 0, + ), + ( + f"--release-folder FOLDER/DOES/NOT/EXIST --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 512, + ), + ( + f"--release-folder true --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 512, + ), + ( + f"--release-folder null --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 512, + ), + ( + f"--release-folder random --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 512, + ), + ], +) +def test_combine_py_release_folder_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} combine {args}") + assert exit_code == expectedExitCode + + +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords 3.8,3.6", + 0, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE}", + 0, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping FAKE/PATH/mapping.yml", + 512, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping fake_mapping.yml", + 512, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping random_string", + 512, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping 0", + 512, + ), + ], +) +def test_combine_py_override_mapping_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} combine {args}") + assert exit_code == expectedExitCode + + +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base {VALID_RELEASE_BASE} --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords 3.8,3.6", + 0, + ), + ( + f"--release-folder {VALID_RELEASE_FOLDER} --release-base INVALID_RELEASE_BASE --override-mapping {VALID_OVERRIDE_MAPPING_FILE} --py_coords 3.8,3.6", + 256, + ), + ], +) +def test_combine_py_release_base_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} combine {args}") + assert exit_code == expectedExitCode + + +# TESTING TRANSPILER +VALID_MATRIX_FILE = abspath(dirname(__file__) + "/data/test_release_matrix.yml") +VALID_OUTPUT_FOLDER = abspath(dirname(__file__)) +VALID_MATRIX_COORDINATES = "{rhel: ['7'], py: ['3.8']}" + + +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER} --matrix-coordinates '{VALID_MATRIX_COORDINATES}'", + 0, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER}", + 0, + ), + ( + f"--matrix-file {dirname(VALID_MATRIX_FILE)} --output-folder {VALID_RELEASE_FOLDER}", + 512, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE}/does_not_exist.yaml --output-folder {VALID_RELEASE_FOLDER}", + 512, + ), + (f"--matrix-file random_string --output-folder {VALID_RELEASE_FOLDER}", 512), + (f"--matrix-file null --output-folder {VALID_RELEASE_FOLDER}", 512), + ], +) +def test_transpile_py_matrix_file_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} transpile {args}") + assert exit_code == expectedExitCode + + +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER} --matrix-coordinates '{VALID_MATRIX_COORDINATES}'", + 0, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER}", + 0, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER}/does_not_exist", + 512, + ), + (f"--matrix-file {VALID_MATRIX_FILE} --output-folder random_string", 512), + (f"--matrix-file {VALID_MATRIX_FILE} --output-folder null", 512), + (f"--matrix-file {VALID_MATRIX_FILE} --output-folder 0", 512), + ], +) +def test_transpile_py_output_folder_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} transpile {args}") + assert exit_code == expectedExitCode + + +@pytest.mark.parametrize( + "args, expectedExitCode", + [ + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER} --matrix-coordinates '{VALID_MATRIX_COORDINATES}'", + 0, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER}", + 0, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER} --matrix-coordinates 0", + 256, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER} --matrix-coordinates random_string", + 256, + ), + ( + f"--matrix-file {VALID_MATRIX_FILE} --output-folder {VALID_RELEASE_FOLDER} --matrix-coordinates false", + 256, + ), + ], +) +def test_transpile_py_matrix_coordinates_type(args, expectedExitCode): + exit_code = os.system(f"{RELEASE_TRANSPILER_FILE_PATH} transpile {args}") + assert exit_code == expectedExitCode