Example #1
0
def test_duplicate_dep_use():
    toml_text = \
'''
[tool.borca]
default_task = "build"

[[tool.borca.tasks]]
name = "build"
commands = [
    "poetry build --format wheel"
]
depends_on = [
    "test",
    "test"
]

[[tool.borca.tasks]]
name = "test"
commands = [
    "pytest"
]
'''
    config = {
        'task-name': 'build',
        'no_hash': False,
        'toml_path': 'pyproject.toml',
        'verbosity': 2
    }
    toml_data = toml.loads(toml_text)
    task_names = [
        task.name for task in Parser(config, toml_data).orderedTasks()
    ]

    assert task_names == ["test", "build"]
Example #2
0
class Orchestrator:
    def __init__(self, config: Dict) -> None:
        self.__config = config
        self.__logger = createLogger('borca.Orchestrator',
                                     self.__config['verbosity'])

        self.__toml = Path(self.__config['toml_path'])

        if (not self.__toml.exists()) or (not self.__toml.is_file()):
            raise InvalidTomlPath(
                f"Could not find pyproject.toml at {self.__config['toml-path']}"
            )

        self.__toml.resolve()

        self.__logger.info(f"Using {self.__toml}")

        self.__toml_data = toml.load(str(self.__toml))

        self.__parser = Parser(self.__config, self.__toml_data)

        self.__executor = Executor(self.__config, self.__parser.orderedTasks())

    def run(self) -> None:
        total_tasks, completed_tasks, cached_tasks = self.__executor.run()

        print(
            f"\n======= [BORCA SUMMARY] =======",
            f"\nTotal Tasks: {total_tasks}"
            f"\nCompleted Tasks: {completed_tasks}"
            f"\nCached Tasks: {cached_tasks}",
            f"\n===============================",
        )
Example #3
0
def test_diamond_dep_tree():
    toml_text = \
'''
[tool.borca]
default_task = "build"

[[tool.borca.tasks]]
name = "build"
commands = [
    "poetry build --format wheel"
]
depends_on = [
    "test",
    "security"
]

[[tool.borca.tasks]]
name = "test"
commands = [
    "pytest"
]
depends_on = [
    "lint"
]

[[tool.borca.tasks]]
name = "security"
commands = [
    "bandit -r borca"
]
depends_on = [
    "lint"
]

[[tool.borca.tasks]]
name = "lint"
commands = [
    "mypy borca",
    "black borca"
]
'''
    config = {
        'task-name': 'build',
        'no_hash': False,
        'toml_path': 'pyproject.toml',
        'verbosity': 2
    }
    toml_data = toml.loads(toml_text)
    task_names = [
        task.name for task in Parser(config, toml_data).orderedTasks()
    ]

    assert (task_names == ["lint", "test", "security", "build"]
            or task_names == ["lint", "security", "test", "build"])
Example #4
0
    def __init__(self, config: Dict) -> None:
        self.__config = config
        self.__logger = createLogger('borca.Orchestrator',
                                     self.__config['verbosity'])

        self.__toml = Path(self.__config['toml_path'])

        if (not self.__toml.exists()) or (not self.__toml.is_file()):
            raise InvalidTomlPath(
                f"Could not find pyproject.toml at {self.__config['toml-path']}"
            )

        self.__toml.resolve()

        self.__logger.info(f"Using {self.__toml}")

        self.__toml_data = toml.load(str(self.__toml))

        self.__parser = Parser(self.__config, self.__toml_data)

        self.__executor = Executor(self.__config, self.__parser.orderedTasks())
Example #5
0
def test_extended_circular_dep_tree():
    toml_text = \
'''
[tool.borca]
default_task = "build"

[[tool.borca.tasks]]
name = "build"
commands = [
    "poetry build --format wheel"
]
depends_on = [
    "test"
]

[[tool.borca.tasks]]
name = "test"
commands = [
    "pytest"
]
depends_on = [
    "lint"
]

[[tool.borca.tasks]]
name = "lint"
commands = [
    "mypy borca",
    "black borca"
]
depends_on = [
    "build"
]

'''
    config = {
        'task-name': 'build',
        'no_hash': False,
        'toml_path': 'pyproject.toml',
        'verbosity': 2
    }
    toml_data = toml.loads(toml_text)
    with pytest.raises(
            InvalidTaskgraph,
            match=
            r"Found circular dependency on task \".*\" to its dependency \".*\""
    ) as e:
        task_names = [
            task.name for task in Parser(config, toml_data).orderedTasks()
        ]
def test_missing_tasks():
    toml_text = \
'''
[tool.borca]
default_task = "build"
'''
    config = {
        'task-name': 'build',
        'no_hash': False,
        'toml_path': 'pyproject.toml',
        'verbosity': 1
    }
    toml_data = toml.loads(toml_text)
    with pytest.raises(pydantic.error_wrappers.ValidationError) as e:
        parser = Parser(config, toml_data)
def test_bad_task_commands_format():
    toml_text = \
'''
[tool.borca]
default_task = "build"

[[tool.borca.tasks]]
name = "build"
commands = "poetry build --format wheel"
'''
    config = {
        'task-name': 'build',
        'no_hash': False,
        'toml_path': 'pyproject.toml',
        'verbosity': 1
    }
    toml_data = toml.loads(toml_text)
    with pytest.raises(pydantic.error_wrappers.ValidationError) as e:
        parser = Parser(config, toml_data)
def test_missing_default_task():
    toml_text = \
'''
[tool.borca]
default_task = "build"

[[tool.borca.tasks]]
name = "test"
commands = [
    "pytest"
]
'''
    config = {
        'task-name': 'build',
        'no_hash': False,
        'toml_path': 'pyproject.toml',
        'verbosity': 1
    }
    toml_data = toml.loads(toml_text)
    with pytest.raises(InvalidToolConfiguration) as e:
        parser = Parser(config, toml_data)