def test_empty_skip_outside_additions(self, project_loader):
        project_loader("empty")

        features.register(CoreFeature())
        features.register(GitignoreFeature())
        load_registered_features()

        action = UpdateGitignoreAction()
        action.execute(target="../outside/to-ignore.yml")

        assert not os.path.exists('.gitignore')
 def test_get_relative_path(self, project_loader):
     assert UpdateGitignoreAction._get_relative_path(
         target='/home/vagrant/sub/to-ignore.yml',
         gitignore='/home/vagrant/.gitignore') == '/sub/to-ignore.yml'
     assert UpdateGitignoreAction._get_relative_path(
         target='/home/vagrant/to-ignore.yml',
         gitignore='/home/vagrant/.gitignore') == '/to-ignore.yml'
     assert UpdateGitignoreAction._get_relative_path(
         target='/home/vagrant/to-ignore.yml',
         gitignore='/home/vagrant/.gitignore',
         first_slash=True) == '/to-ignore.yml'
     assert UpdateGitignoreAction._get_relative_path(
         target='/home/vagrant/to-ignore.yml',
         gitignore='/home/vagrant/.gitignore',
         first_slash=False) == 'to-ignore.yml'
    def test_already_ignored(self, project_loader):
        project_loader("already_ignored")

        assert os.path.exists('.gitignore')
        with open('.gitignore', 'r') as f:
            expected_gitignore = f.read()

        features.register(GitignoreFeature())
        load_registered_features()

        action = UpdateGitignoreAction()
        action.execute(target="./exists.yml")

        assert os.path.exists('.gitignore')
        with open('.gitignore', 'r') as f:
            gitignore = f.read()

        assert gitignore == expected_gitignore
Ejemplo n.º 4
0
def expect_gitignore(gitignore: str, *expected_lines: str):
    in_block_lines = set()

    if os.path.exists(gitignore):
        with open(gitignore, 'r') as file:
            inside_block = False
            for gitignore_line in file.read().splitlines():
                if UpdateGitignoreAction._is_block_limit(gitignore_line, True):
                    inside_block = True
                    continue
                if UpdateGitignoreAction._is_block_limit(
                        gitignore_line, False):
                    inside_block = False
                    continue
                if inside_block:
                    in_block_lines.add(gitignore_line)

    for expected_line in expected_lines:
        if expected_line not in in_block_lines:
            return False

    return True
    def test_empty_project_without_core(self, project_loader):
        project_loader("empty")

        features.register(GitignoreFeature())
        load_registered_features()

        action = UpdateGitignoreAction()
        action.execute(target="./to-ignore.yml")
        action.execute(target="./to-ignore-2.yml")

        assert os.path.exists('.gitignore')
        assert expect_gitignore('.gitignore', '/to-ignore.yml',
                                '/to-ignore-2.yml')