def test_utils_expand_names_not_list(): """Test exception raised if names not a list.""" test_dirs = ['tests/data/tests'] names = 'test_sles' with pytest.raises(IpaUtilsException) as error: ipa_utils.expand_test_files(test_dirs, names) assert str(error.value) == \ 'Names must be a list containing test names and/or test descriptions.'
def test_utils_test_file_not_found(): """Test expand test file does not exist raises exception.""" test_dirs = ['tests/data/tests'] names = ['test_fake'] with pytest.raises(IpaUtilsException) as error: ipa_utils.expand_test_files(test_dirs, names) assert str(error.value) == \ 'Test file with name: test_fake cannot be found.'
def _parse_test_files(self, test_dirs, no_default_test_dirs): """ Collect all test dirs and expand test files. The test files are expanded to absolute paths given test names and a list of availble test dirs to use. """ self.test_dirs = set() if test_dirs: # Command line arg self.test_dirs.update(test_dirs.split(',')) if 'test_dirs' in self.ipa_config: self.test_dirs.update(self.ipa_config['test_dirs'].split(',')) if not no_default_test_dirs: self.test_dirs.update(TEST_PATHS) # Confirm all test dir paths are absolute, unique and # normalized (remove redundant slashes .../ ...// etc.) self.test_dirs = set( os.path.normpath(os.path.expanduser(test_dir)) for test_dir in self.test_dirs) if not self.test_dirs: raise IpaCloudException('At least one test directory is required.') self.test_files = ipa_utils.expand_test_files(self.test_dirs, self.test_files)
def test_utils_expand_test_files(): """Test expand test files utils function.""" test_dirs = ['tests/data/tests'] names = ['test_sles::test_sles', 'test_image_desc'] expanded = ipa_utils.expand_test_files(test_dirs, names) assert 'tests/data/tests/test_image.py' in expanded assert 'tests/data/tests/test_sles.py::test_sles' in expanded
def test_utils_expand_sync_points(): """Test expand test files with sync points.""" test_dirs = ['tests/data/tests'] names = ['test_soft_reboot', 'test_sles_desc', 'test_hard_reboot'] expanded = ipa_utils.expand_test_files(test_dirs, names) assert len(expanded) == 4 assert expanded[0] == 'test_soft_reboot' assert expanded[1] == 'tests/data/tests/test_sles.py' assert expanded[2] == 'tests/data/tests/test_image.py' assert expanded[3] == 'test_hard_reboot'