Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
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'
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
def work(valid_recipe_path, collection_id):
    """Provide Work instance."""

    valid_recipe = Recipe(str(valid_recipe_path), collection_id)
    return Work(valid_recipe)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
def work(valid_recipe_path):
    """Provide Work instance."""

    valid_recipe = Recipe(str(valid_recipe_path), 'rh-ror50')
    return Work(valid_recipe)