From 7d6cf286f236a5a73cd3e2755b11c3ea4f90d1ff Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Thu, 27 Jun 2019 13:23:39 +0200 Subject: [PATCH 1/9] Collecting and cleaning unit test dump --- openml/testing.py | 19 +++++++++++++++++++ tests/test_datasets/test_dataset_functions.py | 14 +++++++++++--- tests/test_tasks/test_split.py | 6 +++++- tests/test_tasks/test_task_functions.py | 8 ++++++++ tests/test_tasks/test_task_methods.py | 9 +++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/openml/testing.py b/openml/testing.py index 1ce0862d03..614764931a 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -103,6 +103,25 @@ def tearDown(self): openml.config.server = self.production_server openml.config.connection_n_retries = self.connection_n_retries + def _track_old_files(self): + files = os.walk(self.static_cache_dir) + self.old_file_list = [] + for root, _, filenames in files: + for filename in filenames: + self.old_file_list.append(os.path.join(root, filename)) + + def _remove_new_files(self): + files = os.walk(self.static_cache_dir) + self.new_file_list = [] + for root, _, filenames in files: + for filename in filenames: + self.new_file_list.append(os.path.join(root, filename)) + # filtering the files generated during this run + self.new_file_list = list(set(self.new_file_list) - + set(self.old_file_list)) + for file in self.new_file_list: + os.remove(file) + def _get_sentinel(self, sentinel=None): if sentinel is None: # Create a unique prefix for the flow. Necessary because the flow diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index 61aeb6904a..6d0f5fcf54 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -1,4 +1,5 @@ import os +import sys import random from itertools import product from unittest import mock @@ -6,6 +7,7 @@ import arff import pytest +import shutil import numpy as np import pandas as pd import scipy.sparse @@ -44,18 +46,24 @@ def tearDown(self): def _remove_pickle_files(self): cache_dir = self.static_cache_dir + self.lock_path = os.path.join(openml.config.get_cache_directory(), 'locks') for did in ['-1', '2']: with lockutils.external_lock( name='datasets.functions.get_dataset:%s' % did, - lock_path=os.path.join(openml.config.get_cache_directory(), 'locks'), + lock_path=self.lock_path, ): - pickle_path = os.path.join(cache_dir, 'datasets', did, - 'dataset.pkl') + if sys.version[0] is '3': + pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', + did, 'dataset.pkl.py3') + else: + pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', + did, 'dataset.pkl') try: os.remove(pickle_path) except (OSError, FileNotFoundError): # Replaced a bare except. Not sure why either of these would be acceptable. pass + shutil.rmtree(self.lock_path, ignore_errors=True) def _get_empty_param_for_dataset(self): diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index 46c6564a13..583667e853 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -1,4 +1,5 @@ import inspect +import sys import os import numpy as np @@ -20,7 +21,10 @@ def setUp(self): "tasks", "1882", "datasplits.arff" ) # TODO Needs to be adapted regarding the python version - self.pd_filename = self.arff_filename.replace(".arff", ".pkl") + if sys.version[0] is '3': + self.pd_filename = self.arff_filename.replace(".arff", ".pkl.py3") + else: + self.pd_filename = self.arff_filename.replace(".arff", ".pkl") def tearDown(self): try: diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index dfdbd4847a..4a6dffd75e 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -12,6 +12,14 @@ class TestTask(TestBase): _multiprocess_can_split_ = True + def setUp(self): + super(TestTask, self).setUp() + self._track_old_files() + + def tearDown(self): + self._remove_new_files() + super(TestTask, self).tearDown() + def test__get_cached_tasks(self): openml.config.cache_directory = self.static_cache_dir tasks = openml.tasks.functions._get_cached_tasks() diff --git a/tests/test_tasks/test_task_methods.py b/tests/test_tasks/test_task_methods.py index 55cbba64b2..d6d33ce162 100644 --- a/tests/test_tasks/test_task_methods.py +++ b/tests/test_tasks/test_task_methods.py @@ -1,3 +1,4 @@ +import os from time import time import openml @@ -7,6 +8,14 @@ # Common methods between tasks class OpenMLTaskMethodsTest(TestBase): + def setUp(self): + super(OpenMLTaskMethodsTest, self).setUp() + self._track_old_files() + + def tearDown(self): + self._remove_new_files() + super(OpenMLTaskMethodsTest, self).tearDown() + def test_tagging(self): task = openml.tasks.get_task(1) tag = "testing_tag_{}_{}".format(self.id(), time()) From 299477a87edb8e0beb01e1e543fb756e94c82541 Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Mon, 1 Jul 2019 16:45:15 +0200 Subject: [PATCH 2/9] Adding session level fixture with yield to delay deletion of files --- openml/testing.py | 55 ++++++++++++------- tests/test_datasets/test_dataset_functions.py | 7 +-- tests/test_tasks/test_split.py | 4 +- tests/test_tasks/test_task_functions.py | 4 +- tests/test_tasks/test_task_methods.py | 5 +- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/openml/testing.py b/openml/testing.py index 614764931a..a333282e78 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -17,6 +17,41 @@ import openml from openml.tasks import TaskTypeEnum +import pytest + + +@pytest.fixture(scope="session", autouse=True) +def cleanup_fixture(): + """Cleans up files generated by Unit tests + + This function is called at the beginning of the invocation of + TestBase (defined below), by each of class that inherits TestBase. + The 'yield' creates a checkpoint and breaks away to continue running + the unit tests of the sub class. When all the tests end, execution + resumes from the checkpoint. + """ + # TODO: generalize this path better akin to static_cache_dir + directory = "{}/tests/files/".format(os.getcwd()) + files = os.walk(directory) + old_file_list = [] + for root, _, filenames in files: + for filename in filenames: + old_file_list.append(os.path.join(root, filename)) + # context switches to other remaining tests + # pauses the code execution here till all tests in the 'session' is over + yield + # resumes from here after all collected tests are completed + files = os.walk(directory) + new_file_list = [] + for root, _, filenames in files: + for filename in filenames: + new_file_list.append(os.path.join(root, filename)) + # filtering the files generated during this run + new_file_list = list(set(new_file_list) - set(old_file_list)) + print("Files to delete: {}".format(new_file_list)) + for file in new_file_list: + os.remove(file) + class TestBase(unittest.TestCase): """Base class for tests @@ -44,7 +79,6 @@ def setUp(self, n_levels: int = 1): Number of nested directories the test is in. Necessary to resolve the path to the ``files`` directory, which is located directly under the ``tests`` directory. """ - # This cache directory is checked in to git to simulate a populated # cache self.maxDiff = None @@ -103,25 +137,6 @@ def tearDown(self): openml.config.server = self.production_server openml.config.connection_n_retries = self.connection_n_retries - def _track_old_files(self): - files = os.walk(self.static_cache_dir) - self.old_file_list = [] - for root, _, filenames in files: - for filename in filenames: - self.old_file_list.append(os.path.join(root, filename)) - - def _remove_new_files(self): - files = os.walk(self.static_cache_dir) - self.new_file_list = [] - for root, _, filenames in files: - for filename in filenames: - self.new_file_list.append(os.path.join(root, filename)) - # filtering the files generated during this run - self.new_file_list = list(set(self.new_file_list) - - set(self.old_file_list)) - for file in self.new_file_list: - os.remove(file) - def _get_sentinel(self, sentinel=None): if sentinel is None: # Create a unique prefix for the flow. Necessary because the flow diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index 6d0f5fcf54..a88df795bd 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -7,7 +7,6 @@ import arff import pytest -import shutil import numpy as np import pandas as pd import scipy.sparse @@ -17,7 +16,7 @@ from openml import OpenMLDataset from openml.exceptions import OpenMLCacheException, OpenMLHashException, \ OpenMLPrivateDatasetError -from openml.testing import TestBase +from openml.testing import TestBase, cleanup_fixture from openml.utils import _tag_entity, _create_cache_directory_for_id from openml.datasets.functions import (create_dataset, attributes_arff_from_df, @@ -45,14 +44,13 @@ def tearDown(self): super(TestOpenMLDataset, self).tearDown() def _remove_pickle_files(self): - cache_dir = self.static_cache_dir self.lock_path = os.path.join(openml.config.get_cache_directory(), 'locks') for did in ['-1', '2']: with lockutils.external_lock( name='datasets.functions.get_dataset:%s' % did, lock_path=self.lock_path, ): - if sys.version[0] is '3': + if sys.version[0] == '3': pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', did, 'dataset.pkl.py3') else: @@ -63,7 +61,6 @@ def _remove_pickle_files(self): except (OSError, FileNotFoundError): # Replaced a bare except. Not sure why either of these would be acceptable. pass - shutil.rmtree(self.lock_path, ignore_errors=True) def _get_empty_param_for_dataset(self): diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index 583667e853..92db5505e3 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -5,7 +5,7 @@ import numpy as np from openml import OpenMLSplit -from openml.testing import TestBase +from openml.testing import TestBase, cleanup_fixture class OpenMLSplitTest(TestBase): @@ -21,7 +21,7 @@ def setUp(self): "tasks", "1882", "datasplits.arff" ) # TODO Needs to be adapted regarding the python version - if sys.version[0] is '3': + if sys.version[0] == '3': self.pd_filename = self.arff_filename.replace(".arff", ".pkl.py3") else: self.pd_filename = self.arff_filename.replace(".arff", ".pkl") diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index 4a6dffd75e..3d2f08a6ab 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -1,7 +1,7 @@ import os from unittest import mock -from openml.testing import TestBase +from openml.testing import TestBase, cleanup_fixture from openml import OpenMLSplit, OpenMLTask from openml.exceptions import OpenMLCacheException import openml @@ -14,10 +14,8 @@ class TestTask(TestBase): def setUp(self): super(TestTask, self).setUp() - self._track_old_files() def tearDown(self): - self._remove_new_files() super(TestTask, self).tearDown() def test__get_cached_tasks(self): diff --git a/tests/test_tasks/test_task_methods.py b/tests/test_tasks/test_task_methods.py index d6d33ce162..0d28d3e8b7 100644 --- a/tests/test_tasks/test_task_methods.py +++ b/tests/test_tasks/test_task_methods.py @@ -1,8 +1,7 @@ -import os from time import time import openml -from openml.testing import TestBase +from openml.testing import TestBase, cleanup_fixture # Common methods between tasks @@ -10,10 +9,8 @@ class OpenMLTaskMethodsTest(TestBase): def setUp(self): super(OpenMLTaskMethodsTest, self).setUp() - self._track_old_files() def tearDown(self): - self._remove_new_files() super(OpenMLTaskMethodsTest, self).tearDown() def test_tagging(self): From 5ecafe8b0725b7b51095e264d466e2e804f96bb1 Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Wed, 3 Jul 2019 15:20:23 +0200 Subject: [PATCH 3/9] Adding PEP8 ignore F401 --- ci_scripts/flake8_diff.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci_scripts/flake8_diff.sh b/ci_scripts/flake8_diff.sh index d745773410..696e8c7f34 100755 --- a/ci_scripts/flake8_diff.sh +++ b/ci_scripts/flake8_diff.sh @@ -3,5 +3,5 @@ # Update /CONTRIBUTING.md if these commands change. # The reason for not advocating using this script directly is that it # might not work out of the box on Windows. -flake8 --ignore E402,W503 --show-source --max-line-length 100 $options +flake8 --ignore E402,W503,F401 --show-source --max-line-length 100 $options mypy openml --ignore-missing-imports --follow-imports skip From 758aa3082931144051a234b1f7ffe56f6a38e261 Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Wed, 3 Jul 2019 15:29:49 +0200 Subject: [PATCH 4/9] Changelog update + pytest argument fix --- ci_scripts/test.sh | 2 +- doc/progress.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index 80b35f04f0..2a837583e4 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -22,7 +22,7 @@ run_tests() { PYTEST_ARGS='' fi - pytest -n 4 --duration=20 --timeout=600 --timeout-method=thread -sv --ignore='test_OpenMLDemo.py' $PYTEST_ARGS $test_dir + pytest -n 4 --durations=20 --timeout=600 --timeout-method=thread -sv --ignore='test_OpenMLDemo.py' $PYTEST_ARGS $test_dir } if [[ "$RUN_FLAKE8" == "true" ]]; then diff --git a/doc/progress.rst b/doc/progress.rst index 83e46d494d..bc00fd300a 100644 --- a/doc/progress.rst +++ b/doc/progress.rst @@ -11,6 +11,7 @@ Changelog * ADD #687: Adds a function to retrieve the list of evaluation measures available. * ADD #695: A function to retrieve all the data quality measures available. +* FIX #447: All files created by unit tests no longer persist. 0.9.0 ~~~~~ From 2bc519e3a652d985a82d452186be48d5dfebcea8 Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Thu, 4 Jul 2019 16:37:50 +0200 Subject: [PATCH 5/9] Leaner implementation without additional imports --- ci_scripts/flake8_diff.sh | 2 +- openml/testing.py | 65 +++++++++---------- tests/test_datasets/test_dataset_functions.py | 2 +- tests/test_tasks/test_split.py | 2 +- tests/test_tasks/test_task_functions.py | 2 +- tests/test_tasks/test_task_methods.py | 2 +- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/ci_scripts/flake8_diff.sh b/ci_scripts/flake8_diff.sh index 696e8c7f34..d745773410 100755 --- a/ci_scripts/flake8_diff.sh +++ b/ci_scripts/flake8_diff.sh @@ -3,5 +3,5 @@ # Update /CONTRIBUTING.md if these commands change. # The reason for not advocating using this script directly is that it # might not work out of the box on Windows. -flake8 --ignore E402,W503,F401 --show-source --max-line-length 100 $options +flake8 --ignore E402,W503 --show-source --max-line-length 100 $options mypy openml --ignore-missing-imports --follow-imports skip diff --git a/openml/testing.py b/openml/testing.py index a333282e78..0162379f1a 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -20,39 +20,6 @@ import pytest -@pytest.fixture(scope="session", autouse=True) -def cleanup_fixture(): - """Cleans up files generated by Unit tests - - This function is called at the beginning of the invocation of - TestBase (defined below), by each of class that inherits TestBase. - The 'yield' creates a checkpoint and breaks away to continue running - the unit tests of the sub class. When all the tests end, execution - resumes from the checkpoint. - """ - # TODO: generalize this path better akin to static_cache_dir - directory = "{}/tests/files/".format(os.getcwd()) - files = os.walk(directory) - old_file_list = [] - for root, _, filenames in files: - for filename in filenames: - old_file_list.append(os.path.join(root, filename)) - # context switches to other remaining tests - # pauses the code execution here till all tests in the 'session' is over - yield - # resumes from here after all collected tests are completed - files = os.walk(directory) - new_file_list = [] - for root, _, filenames in files: - for filename in filenames: - new_file_list.append(os.path.join(root, filename)) - # filtering the files generated during this run - new_file_list = list(set(new_file_list) - set(old_file_list)) - print("Files to delete: {}".format(new_file_list)) - for file in new_file_list: - os.remove(file) - - class TestBase(unittest.TestCase): """Base class for tests @@ -62,6 +29,38 @@ class TestBase(unittest.TestCase): Hopefully soon allows using a test server, not the production server. """ + @pytest.fixture(scope="session", autouse=True) + def _cleanup_fixture(self): + """Cleans up files generated by Unit tests + + This function is called at the beginning of the invocation of + TestBase (defined below), by each of class that inherits TestBase. + The 'yield' creates a checkpoint and breaks away to continue running + the unit tests of the sub class. When all the tests end, execution + resumes from the checkpoint. + """ + # TODO: generalize this path better akin to static_cache_dir + directory = "{}/tests/files/".format(os.getcwd()) + files = os.walk(directory) + old_file_list = [] + for root, _, filenames in files: + for filename in filenames: + old_file_list.append(os.path.join(root, filename)) + # context switches to other remaining tests + # pauses the code execution here till all tests in the 'session' is over + yield + # resumes from here after all collected tests are completed + files = os.walk(directory) + new_file_list = [] + for root, _, filenames in files: + for filename in filenames: + new_file_list.append(os.path.join(root, filename)) + # filtering the files generated during this run + new_file_list = list(set(new_file_list) - set(old_file_list)) + print("Files to delete in local: {}".format(new_file_list)) + for file in new_file_list: + os.remove(file) + def setUp(self, n_levels: int = 1): """Setup variables and temporary directories. diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index a88df795bd..fb22709527 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -16,7 +16,7 @@ from openml import OpenMLDataset from openml.exceptions import OpenMLCacheException, OpenMLHashException, \ OpenMLPrivateDatasetError -from openml.testing import TestBase, cleanup_fixture +from openml.testing import TestBase from openml.utils import _tag_entity, _create_cache_directory_for_id from openml.datasets.functions import (create_dataset, attributes_arff_from_df, diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index 92db5505e3..bbb2a26000 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -5,7 +5,7 @@ import numpy as np from openml import OpenMLSplit -from openml.testing import TestBase, cleanup_fixture +from openml.testing import TestBase class OpenMLSplitTest(TestBase): diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index 3d2f08a6ab..f773752d55 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -1,7 +1,7 @@ import os from unittest import mock -from openml.testing import TestBase, cleanup_fixture +from openml.testing import TestBase from openml import OpenMLSplit, OpenMLTask from openml.exceptions import OpenMLCacheException import openml diff --git a/tests/test_tasks/test_task_methods.py b/tests/test_tasks/test_task_methods.py index 0d28d3e8b7..4a07894148 100644 --- a/tests/test_tasks/test_task_methods.py +++ b/tests/test_tasks/test_task_methods.py @@ -1,7 +1,7 @@ from time import time import openml -from openml.testing import TestBase, cleanup_fixture +from openml.testing import TestBase # Common methods between tasks From c25018547e531e1ebeeea096092906f06e021421 Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Mon, 8 Jul 2019 13:30:12 +0200 Subject: [PATCH 6/9] Removing TODO --- openml/testing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openml/testing.py b/openml/testing.py index 0162379f1a..98edd081ad 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -39,7 +39,6 @@ def _cleanup_fixture(self): the unit tests of the sub class. When all the tests end, execution resumes from the checkpoint. """ - # TODO: generalize this path better akin to static_cache_dir directory = "{}/tests/files/".format(os.getcwd()) files = os.walk(directory) old_file_list = [] From 3597b9da22f0c0060fb04e3c27ab79933b71054e Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Tue, 9 Jul 2019 11:06:52 +0200 Subject: [PATCH 7/9] Making changes suggested --- doc/progress.rst | 2 +- openml/testing.py | 73 +++++++++++-------- tests/test_datasets/test_dataset_functions.py | 9 +-- tests/test_tasks/test_split.py | 7 +- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/doc/progress.rst b/doc/progress.rst index bc00fd300a..3878f91244 100644 --- a/doc/progress.rst +++ b/doc/progress.rst @@ -11,7 +11,7 @@ Changelog * ADD #687: Adds a function to retrieve the list of evaluation measures available. * ADD #695: A function to retrieve all the data quality measures available. -* FIX #447: All files created by unit tests no longer persist. +* FIX #447: All files created by unit tests are deleted after the completion of all unit tests. 0.9.0 ~~~~~ diff --git a/openml/testing.py b/openml/testing.py index 98edd081ad..9b6649c976 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -29,37 +29,6 @@ class TestBase(unittest.TestCase): Hopefully soon allows using a test server, not the production server. """ - @pytest.fixture(scope="session", autouse=True) - def _cleanup_fixture(self): - """Cleans up files generated by Unit tests - - This function is called at the beginning of the invocation of - TestBase (defined below), by each of class that inherits TestBase. - The 'yield' creates a checkpoint and breaks away to continue running - the unit tests of the sub class. When all the tests end, execution - resumes from the checkpoint. - """ - directory = "{}/tests/files/".format(os.getcwd()) - files = os.walk(directory) - old_file_list = [] - for root, _, filenames in files: - for filename in filenames: - old_file_list.append(os.path.join(root, filename)) - # context switches to other remaining tests - # pauses the code execution here till all tests in the 'session' is over - yield - # resumes from here after all collected tests are completed - files = os.walk(directory) - new_file_list = [] - for root, _, filenames in files: - for filename in filenames: - new_file_list.append(os.path.join(root, filename)) - # filtering the files generated during this run - new_file_list = list(set(new_file_list) - set(old_file_list)) - print("Files to delete in local: {}".format(new_file_list)) - for file in new_file_list: - os.remove(file) - def setUp(self, n_levels: int = 1): """Setup variables and temporary directories. @@ -135,6 +104,48 @@ def tearDown(self): openml.config.server = self.production_server openml.config.connection_n_retries = self.connection_n_retries + @pytest.fixture(scope="session", autouse=True) + def _cleanup_fixture(self): + """Cleans up files generated by Unit tests + + This function is called at the beginning of the invocation of + TestBase (defined below), by each of class that inherits TestBase. + The 'yield' creates a checkpoint and breaks away to continue running + the unit tests of the sub class. When all the tests end, execution + resumes from the checkpoint. + """ + + abspath_this_file = os.path.abspath(inspect.getfile(self.__class__)) + static_cache_dir = os.path.dirname(abspath_this_file) + # Could be a risky while condition, however, going up a directory + # n-times will eventually end at main directory + while True: + if 'openml' in os.listdir(static_cache_dir): + break + else: + static_cache_dir = os.path.join(static_cache_dir, '../') + directory = os.path.join(static_cache_dir, 'tests/files/') + # directory = "{}/tests/files/".format(static_cache_dir) + files = os.walk(directory) + old_file_list = [] + for root, _, filenames in files: + for filename in filenames: + old_file_list.append(os.path.join(root, filename)) + # context switches to other remaining tests + # pauses the code execution here till all tests in the 'session' is over + yield + # resumes from here after all collected tests are completed + files = os.walk(directory) + new_file_list = [] + for root, _, filenames in files: + for filename in filenames: + new_file_list.append(os.path.join(root, filename)) + # filtering the files generated during this run + new_file_list = list(set(new_file_list) - set(old_file_list)) + print("Files to delete in local: {}".format(new_file_list)) + for file in new_file_list: + os.remove(file) + def _get_sentinel(self, sentinel=None): if sentinel is None: # Create a unique prefix for the flow. Necessary because the flow diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index fb22709527..605385e889 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -1,5 +1,4 @@ import os -import sys import random from itertools import product from unittest import mock @@ -50,12 +49,8 @@ def _remove_pickle_files(self): name='datasets.functions.get_dataset:%s' % did, lock_path=self.lock_path, ): - if sys.version[0] == '3': - pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', - did, 'dataset.pkl.py3') - else: - pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', - did, 'dataset.pkl') + pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', + did, 'dataset.pkl.py3') try: os.remove(pickle_path) except (OSError, FileNotFoundError): diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index bbb2a26000..763bb15f79 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -1,5 +1,4 @@ import inspect -import sys import os import numpy as np @@ -20,11 +19,7 @@ def setUp(self): self.directory, "..", "files", "org", "openml", "test", "tasks", "1882", "datasplits.arff" ) - # TODO Needs to be adapted regarding the python version - if sys.version[0] == '3': - self.pd_filename = self.arff_filename.replace(".arff", ".pkl.py3") - else: - self.pd_filename = self.arff_filename.replace(".arff", ".pkl") + self.pd_filename = self.arff_filename.replace(".arff", ".pkl.py3") def tearDown(self): try: From ce30c674ef81ef479787f6d8b08c75763b84b192 Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Tue, 9 Jul 2019 11:40:03 +0200 Subject: [PATCH 8/9] Editing CI script to check for files after unit testing --- ci_scripts/test.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index 2a837583e4..da116324d6 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -1,5 +1,8 @@ set -e +before="`git status --porcelain -b`" +before="$before" + run_tests() { # Get into a temp directory to run test from the installed scikit learn and # check if we do not leave artifacts @@ -32,3 +35,9 @@ fi if [[ "$SKIP_TESTS" != "true" ]]; then run_tests fi + +after="`git status --porcelain -b`" +if [[ "$before" != "$after" ]]; then + echo "All generated files have not been deleted!" + exit 1 +fi \ No newline at end of file From 1a6044c5513c84b844a7bc503e2b00923afc75fc Mon Sep 17 00:00:00 2001 From: neeratyoy Date: Tue, 9 Jul 2019 12:47:29 +0200 Subject: [PATCH 9/9] Adding comments to shell script change --- ci_scripts/test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index da116324d6..51ecace497 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -1,5 +1,6 @@ set -e +# check status and branch before running the unit tests before="`git status --porcelain -b`" before="$before" @@ -36,6 +37,8 @@ if [[ "$SKIP_TESTS" != "true" ]]; then run_tests fi +# check status and branch after running the unit tests +# compares with $before to check for remaining files after="`git status --porcelain -b`" if [[ "$before" != "$after" ]]; then echo "All generated files have not been deleted!"