def test_close(): mock_recipe = mock.MagicMock() type(mock_recipe).num_of_package = mock.PropertyMock(return_value=2) work = Work(mock_recipe) assert work work.close() assert not os.path.isdir(work.working_dir)
def test_each_num_dir(): work = None try: mock_recipe = mock.MagicMock() type(mock_recipe).num_of_package = mock.PropertyMock(return_value=2) package_dicts = [ { 'name': 'a' }, { 'name': 'b' }, ] mock_recipe.each_normalized_package.return_value = iter(package_dicts) work = Work(mock_recipe) assert work for package_dict, num_name in work.each_num_dir(): assert package_dict assert num_name assert re.match('^[12]$', num_name) assert re.match('^.+/[12]$', os.getcwd()) with helper.pushd(work.working_dir): assert os.path.isdir('1') assert os.path.isdir('2') finally: work.close()
def builder(valid_recipe_path): """Provide initialized BaseBuilder.""" recipe = Recipe(str(valid_recipe_path), 'rh-ror50') work = Work(recipe) builder = BaseBuilder(work, pkg_cmd='testpkg') return builder
def run_internally(self, argv): work = None try: args = self.parse_argv(argv) # Load recipe recipe = Recipe(args.recipe_file, args.recipe_id) args_dict = vars(args) work = Work(recipe, **args_dict) # Load downloader downloader = BaseDownloader.get_instance(args.download) # Load builder builder = BaseBuilder.get_instance(args.build) # Run downloader LOG.info('Downloading...') downloader.run(work, **args_dict) # Run builder LOG.info('Building...') builder.run(work, **args_dict) LOG.info('Done successfully.') except Exception as e: # work.close raise e finally: # work.close pass
def test_num_name_from_count(): mock_recipe = mock.MagicMock() type(mock_recipe).num_of_package = mock.PropertyMock(return_value=11) with closing(Work(mock_recipe)) as work: assert work assert work.num_name_from_count(2) == '02' assert work.num_name_from_count(10) == '10'
def test_init(): work = None mock_recipe = mock.MagicMock() mock_recipe.num_of_package.return_value = 2 try: work = Work(mock_recipe) assert work finally: working_dir = work.working_dir assert working_dir assert re.findall(r'/tmp/', working_dir) if os.path.isdir(working_dir): shutil.rmtree(working_dir)
def test_init_work_directory(): work = None arg_working_dir = None mock_recipe = mock.MagicMock() mock_recipe.num_of_package.return_value = 2 try: arg_working_dir = tempfile.mkdtemp(prefix='rpmlb-test-') work = Work(mock_recipe, work_directory=arg_working_dir) assert work finally: working_dir = work.working_dir assert working_dir assert working_dir == arg_working_dir if os.path.isdir(working_dir): shutil.rmtree(working_dir)
def test_num_name_from_count(): work = None try: mock_recipe = mock.MagicMock() type(mock_recipe).num_of_package = mock.PropertyMock(return_value=11) work = Work(mock_recipe) assert work assert work.num_name_from_count(2) == '02' assert work.num_name_from_count(10) == '10' finally: work.close()
def work(valid_recipe_path, collection_id): """Provide Work instance.""" valid_recipe = Recipe(str(valid_recipe_path), collection_id) return Work(valid_recipe)
def test_init_raises_error_without_pkg_cmd_option(valid_recipe_path): recipe = Recipe(str(valid_recipe_path), 'rh-ror50') work = Work(recipe) with pytest.raises(ValueError): BaseBuilder(work)
def work(valid_recipe_path): """Provide Work instance.""" valid_recipe = Recipe(str(valid_recipe_path), 'rh-ror50') return Work(valid_recipe)