From 9093ab3f47d012f18efa4baf05ade114549c5699 Mon Sep 17 00:00:00 2001 From: Jasper Berton Date: Fri, 17 Nov 2023 09:14:57 +0100 Subject: [PATCH] tests back operational with github actions --- .../Subset/SubsetTemplateCreatorTests.py | 69 ------------------- .../Subset/SubsetTemplateCreator_test.py | 57 ++++++++++----- UnitTests/run_all_tests.py | 4 +- 3 files changed, 42 insertions(+), 88 deletions(-) delete mode 100644 UnitTests/Subset/SubsetTemplateCreatorTests.py diff --git a/UnitTests/Subset/SubsetTemplateCreatorTests.py b/UnitTests/Subset/SubsetTemplateCreatorTests.py deleted file mode 100644 index 614454a..0000000 --- a/UnitTests/Subset/SubsetTemplateCreatorTests.py +++ /dev/null @@ -1,69 +0,0 @@ - -import os -import shutil -from pathlib import Path - -import pytest - -from otlmow_template.SubsetTemplateCreator import SubsetTemplateCreator - -ROOT_DIR = Path(__file__).parent - - -# Toegangsprocedure en Agent zijn niet meer in de subset aanwezig -def test_func1(subtests): - subset_tool = SubsetTemplateCreator() - subset_location = ROOT_DIR / 'Flitspaal_noAgent3.0.db' - xls_location = Path(ROOT_DIR) / 'testFileStorage' / 'template_file_text.xlsx' - csv_location = Path(ROOT_DIR) / 'testFileStorage' / 'template_file_text.csv' - - with subtests.test(msg='xls'): - subset_tool.generate_template_from_subset(path_to_subset=subset_location, - path_to_template_file_and_extension=xls_location, - ) - assert Path(ROOT_DIR / 'testFileStorage' / 'template_file_text.xlsx').exists() - - with subtests.test(msg='csv, split per type'): - subset_tool.generate_template_from_subset(path_to_subset=subset_location, - path_to_template_file_and_extension=csv_location, - split_per_type=True) - - with subtests.test(msg='csv, not split per type'): - subset_tool.generate_template_from_subset(path_to_subset=subset_location, - path_to_template_file_and_extension=csv_location, - split_per_type=False) - assert Path(ROOT_DIR / 'testFileStorage' / 'template_file_text.csv').exists() - - shutil.rmtree(Path(ROOT_DIR) / 'testFileStorage') - os.makedirs(Path(ROOT_DIR) / 'testFileStorage') - - -def test_subset_actual_subset(): - subset_tool = SubsetTemplateCreator() - csv_location = ROOT_DIR / 'testFileStorage' / 'camera_steun.csv' - subset_tool.generate_template_from_subset(path_to_subset=ROOT_DIR / 'camera_steun.db', - path_to_template_file_and_extension=csv_location, - split_per_type=True) - csv1 = ROOT_DIR / 'testFileStorage' / 'camera_steun_onderdeel_Bevestiging.csv' - csv2 = ROOT_DIR / 'testFileStorage' / 'camera_steun_onderdeel_Camera.csv' - csv3 = ROOT_DIR / 'testFileStorage' / 'camera_steun_onderdeel_RechteSteun.csv' - assert csv1.exists() - assert csv2.exists() - assert csv3.exists() - shutil.rmtree(Path(ROOT_DIR) / 'testFileStorage') - os.makedirs(Path(ROOT_DIR) / 'testFileStorage') - - -def test_filter(): - db_location = ROOT_DIR / 'flitspaal_noAgent3.0.db' - list_of_filter_uri = ['https://wegenenverkeer.data.vlaanderen.be/ns/installatie#Flitspaal'] - filtered = SubsetTemplateCreator.filters_assets_by_subset(db_location, list_of_filter_uri) - assert len(filtered) == 1 - assert filtered[0].name == 'Flitspaal' - - -def test_empty_filter_list_removes_all_entries(): - db_location = ROOT_DIR / 'flitspaal_noAgent3.0.db' - list_of_filter_uri = [] - filtered = SubsetTemplateCreator.filters_assets_by_subset(db_location, list_of_filter_uri) - assert len(filtered) == 0 \ No newline at end of file diff --git a/UnitTests/Subset/SubsetTemplateCreator_test.py b/UnitTests/Subset/SubsetTemplateCreator_test.py index 6bcd5ae..fe38db4 100644 --- a/UnitTests/Subset/SubsetTemplateCreator_test.py +++ b/UnitTests/Subset/SubsetTemplateCreator_test.py @@ -1,47 +1,68 @@ import os -import unittest +import shutil from pathlib import Path +import pytest + from otlmow_template.SubsetTemplateCreator import SubsetTemplateCreator -ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) +ROOT_DIR = Path(__file__).parent -def test_basic_functionality(subtests): +# Toegangsprocedure en Agent zijn niet meer in de subset aanwezig +def test_func1(subtests): subset_tool = SubsetTemplateCreator() - subset_location = Path(ROOT_DIR) / 'OTL_AllCasesTestClass.db' - xls_location = Path(ROOT_DIR) / 'template_file_text.xlsx' - csv_location = Path(ROOT_DIR) / 'template_file_text.csv' + subset_location = ROOT_DIR / 'Flitspaal_noAgent3.0.db' + xls_location = Path(ROOT_DIR) / 'testFileStorage' / 'template_file_text.xlsx' + csv_location = Path(ROOT_DIR) / 'testFileStorage' / 'template_file_text.csv' - with subtests.test(msg='xlsx'): + with subtests.test(msg='xls'): subset_tool.generate_template_from_subset(path_to_subset=subset_location, path_to_template_file_and_extension=xls_location, - class_directory='UnitTests.TestClasses.Classes') + ) + assert Path(ROOT_DIR / 'testFileStorage' / 'template_file_text.xlsx').exists() with subtests.test(msg='csv, split per type'): subset_tool.generate_template_from_subset(path_to_subset=subset_location, path_to_template_file_and_extension=csv_location, - class_directory='UnitTests.TestClasses.Classes', split_per_type=True) + with subtests.test(msg='csv, not split per type'): subset_tool.generate_template_from_subset(path_to_subset=subset_location, path_to_template_file_and_extension=csv_location, - class_directory='UnitTests.TestClasses.Classes', split_per_type=False) + assert Path(ROOT_DIR / 'testFileStorage' / 'template_file_text.csv').exists() - # TODO assert missing + shutil.rmtree(Path(ROOT_DIR) / 'testFileStorage') + os.makedirs(Path(ROOT_DIR) / 'testFileStorage') def test_subset_actual_subset(): subset_tool = SubsetTemplateCreator() - csv_location = Path(ROOT_DIR) / 'camera_steun.csv' - subset_tool.generate_template_from_subset(path_to_subset=Path(ROOT_DIR) / 'camera_steun.db', + csv_location = ROOT_DIR / 'testFileStorage' / 'camera_steun.csv' + subset_tool.generate_template_from_subset(path_to_subset=ROOT_DIR / 'camera_steun.db', path_to_template_file_and_extension=csv_location, split_per_type=True) - # TODO assert missing + csv1 = ROOT_DIR / 'testFileStorage' / 'camera_steun_onderdeel_Bevestiging.csv' + csv2 = ROOT_DIR / 'testFileStorage' / 'camera_steun_onderdeel_Camera.csv' + csv3 = ROOT_DIR / 'testFileStorage' / 'camera_steun_onderdeel_RechteSteun.csv' + assert csv1.exists() + assert csv2.exists() + assert csv3.exists() + shutil.rmtree(Path(ROOT_DIR) / 'testFileStorage') + os.makedirs(Path(ROOT_DIR) / 'testFileStorage') + + +def test_filter(): + db_location = ROOT_DIR / 'flitspaal_noAgent3.0.db' + list_of_filter_uri = ['https://wegenenverkeer.data.vlaanderen.be/ns/installatie#Flitspaal'] + filtered = SubsetTemplateCreator.filters_assets_by_subset(db_location, list_of_filter_uri) + assert len(filtered) == 1 + assert filtered[0].name == 'Flitspaal' -@unittest.skip -def test_func2(): - list_of_otl_objects = [] - SubsetTemplateCreator.filters_assets_by_subset(Path('OTL_AllCasesTestClass.db'), list_of_otl_objects) +def test_empty_filter_list_removes_all_entries(): + db_location = ROOT_DIR / 'flitspaal_noAgent3.0.db' + list_of_filter_uri = [] + filtered = SubsetTemplateCreator.filters_assets_by_subset(db_location, list_of_filter_uri) + assert len(filtered) == 0 \ No newline at end of file diff --git a/UnitTests/run_all_tests.py b/UnitTests/run_all_tests.py index 304c47c..77cace0 100644 --- a/UnitTests/run_all_tests.py +++ b/UnitTests/run_all_tests.py @@ -1,4 +1,6 @@ -import os, pathlib +import os +import pathlib + import pytest os.chdir(pathlib.Path.cwd())