Exemple #1
0
    def test_create_exists_no_overwrite(self, mocker):
        """Don't overwrite a config file."""
        mocked_exists = mocker.patch.object(Path, "exists", autospec=True)
        mocked_exists.return_value = True
        mocked_copy = mocker.patch.object(Path, "copy", autospec=True)
        mocked_path = mocker.patch("dependencmake.config.path", autospec=True)
        mocked_path.return_value.__enter__.return_value = (
            Pathlib("resources") / "dependencmake.yaml")
        mocked_input = mocker.patch("dependencmake.config.input")
        mocked_input.return_value = "no"

        create_config(Path("path"))

        mocked_copy.assert_not_called()
Exemple #2
0
    def test_create_exists_force(self, mocker):
        """Force overwrite a config file."""
        mocked_exists = mocker.patch.object(Path, "exists", autospec=True)
        mocked_exists.return_value = True
        mocked_copy = mocker.patch.object(Path, "copy", autospec=True)
        mocked_path = mocker.patch("dependencmake.config.path", autospec=True)
        mocked_path.return_value.__enter__.return_value = (
            Pathlib("resources") / "dependencmake.yaml")

        create_config(Path("path"), True)

        mocked_copy.assert_called_with(
            Path("resources") / "dependencmake.yaml",
            Path("path") / "dependencmake.yaml",
        )
Exemple #3
0
    def test_create(self, mocker):
        """Create a config file in empty directory."""
        mocked_exists = mocker.patch.object(Path, "exists", autospec=True)
        mocked_exists.return_value = False
        mocked_copy = mocker.patch.object(Path, "copy", autospec=True)
        mocked_path = mocker.patch("dependencmake.config.path", autospec=True)
        mocked_path.return_value.__enter__.return_value = (
            Pathlib("resources") / "dependencmake.yaml")

        create_config(Path("path"))

        mocked_exists.assert_called_with(Path("path") / "dependencmake.yaml")
        mocked_path.assert_called()
        mocked_copy.assert_called_with(
            Path("resources") / "dependencmake.yaml",
            Path("path") / "dependencmake.yaml",
        )
Exemple #4
0
def run_create_config(args: Namespace, output=sys.stdout):
    """Run the create-config command."""
    create_config(args.path, args.force)

    output.write(f"Config file created in {CONFIG_NAME}\n")