Example #1
0
 def test_commit_changes(self, tmp_path, caplog):
     home, repo = self.setup_repo(tmp_path, 'file')
     git = Git(str(repo))
     open(home / 'file', 'w').close()
     assert main(args=['update'], cwd=str(repo), home=str(home)) == 0
     assert main(args=['commit'], cwd=str(repo), home=str(home)) == 0
     assert 'not changes detected' not in caplog.text
     assert 'filelist' in git.last_commit()
Example #2
0
    def setup_repo(self, tmp_path, flist=""):
        home = tmp_path / 'home'
        repo = tmp_path / 'repo'
        os.makedirs(home)
        os.makedirs(repo)
        main(args=['init'], cwd=str(repo))
        with open(repo / 'filelist', 'w') as f:
            f.write(flist)

        return home, repo
Example #3
0
    def test_clean(self, tmp_path):
        home, repo = self.setup_repo(tmp_path, 'file')
        open(home / 'file', 'w').close()

        assert main(args=['update'], cwd=str(repo), home=str(home)) == 0
        assert (home / 'file').is_symlink()
        assert repo in (home / 'file').resolve().parents

        assert main(args=['clean'], cwd=str(repo), home=str(home)) == 0
        assert not (home / 'file').exists()
Example #4
0
    def test_restore_nohome_repo(self, tmp_path):
        home, repo = self.setup_repo(tmp_path, 'file')
        open(home / 'file', 'w').close()

        assert main(args=['update'], cwd=str(repo), home=str(home)) == 0
        assert (home / 'file').is_symlink()
        assert repo in (home / 'file').resolve().parents

        os.remove(home / 'file')
        assert main(args=['restore'], cwd=str(repo), home=str(home)) == 0
        assert (home / 'file').is_symlink()
        assert repo in (home / 'file').resolve().parents
Example #5
0
    def test_add_remove_restore(self, tmp_path):
        home, repo = self.setup_repo(tmp_path, "foo")

        (home / "foo").touch()
        main(args=['update'], cwd=str(repo), home=str(home))

        assert (home / "foo").is_symlink()
        assert (home / "foo").exists()

        (home / "foo").unlink()
        main(args=['restore'], cwd=str(repo), home=str(home))

        assert (home / "foo").is_symlink()
        assert (home / "foo").exists()
Example #6
0
    def test_passwd_nonempty(self, tmp_path, monkeypatch):
        home, repo = self.setup_repo(tmp_path, 'file|encrypt')

        password = '******'
        monkeypatch.setattr('getpass.getpass', lambda prompt: password)

        (home / 'file').touch()
        assert main(args=['update'], cwd=str(repo), home=str(home)) == 0

        repo_file = repo / 'dotfiles' / 'encrypt' / 'common' / 'file'
        txt = repo_file.read_text()

        assert main(args=['passwd'], cwd=str(repo), home=str(home)) == 0
        assert repo_file.read_text() != txt
Example #7
0
    def test_restore_home_repo(self, tmp_path, monkeypatch):
        home, repo = self.setup_repo(tmp_path, 'file')
        open(home / 'file', 'w').close()

        assert main(args=['update'], cwd=str(repo), home=str(home)) == 0

        monkeypatch.setattr('builtins.input', lambda p: 'y')

        os.remove(home / 'file')
        open(home / 'file', 'w').close()

        assert main(args=['restore'], cwd=str(repo), home=str(home)) == 0

        assert (home / 'file').is_symlink()
        assert repo in (home / 'file').resolve().parents
Example #8
0
    def test_reinit(self, tmp_path, caplog):
        home = tmp_path / 'home'
        repo = tmp_path / 'repo'
        os.makedirs(home)
        os.makedirs(repo)

        assert main(args=['init'], cwd=str(repo), home=str(home)) == 0
        assert main(args=['init'], cwd=str(repo), home=str(home)) == 0
        git = Git(str(repo))

        assert (repo / '.git').is_dir()
        assert (repo / 'filelist').is_file()
        assert git.last_commit() == 'Added filelist'
        assert len(git.commits()) == 1

        assert 'existing git repo' in caplog.text
        assert 'existing filelist' in caplog.text
Example #9
0
    def test_init_home(self, tmp_path, caplog):
        home = tmp_path / 'home'
        repo = tmp_path / 'repo'
        os.makedirs(home)
        os.makedirs(repo)

        assert main(args=['init'], cwd=str(home), home=str(home)) != 0
        assert 'safety checks failed' in caplog.text
Example #10
0
    def test_restore_hard_nohome_repo(self, tmp_path):
        home, repo = self.setup_repo(tmp_path, 'file')
        data = 'test data'
        with open(home / 'file', 'w') as f:
            f.write(data)

        assert main(args=['update'], cwd=str(repo), home=str(home)) == 0
        assert (home / 'file').is_symlink()
        assert repo in (home / 'file').resolve().parents

        os.remove(home / 'file')
        assert not (home / 'file').exists()
        assert main(args=['restore', '--hard'], cwd=str(repo),
                    home=str(home)) == 0
        assert (home / 'file').exists()
        assert not (home / 'file').is_symlink()
        assert (home / 'file').read_text() == data
Example #11
0
    def test_passwd_empty(self, tmp_path, monkeypatch):
        home, repo = self.setup_repo(tmp_path, 'file\nfile2')

        password = '******'
        monkeypatch.setattr('getpass.getpass', lambda prompt: password)

        assert not (repo / '.plugins' / 'encrypt' / 'passwd').exists()
        assert main(args=['passwd'], cwd=str(repo), home=str(home)) == 0
        assert (repo / '.plugins' / 'encrypt' / 'passwd').exists()
Example #12
0
    def test_dry_run(self, tmp_path):
        home, repo = self.setup_repo(tmp_path, 'file')
        open(home / 'file', 'w').close()

        assert main(args=['update', '--dry-run'],
                    cwd=str(repo),
                    home=str(home)) == 0
        assert (home / 'file').exists()
        assert not (home / 'file').is_symlink()
Example #13
0
    def test_diff(self, tmp_path, capsys):
        home, repo = self.setup_repo(tmp_path, 'file\nfile2')
        (home / 'file').touch()
        (home / 'file2').touch()

        ret = main(args=['update', '--hard'], cwd=str(repo), home=str(home))
        assert ret == 0

        (home / 'file').write_text('hello world')

        ret = main(args=['diff', '--hard'], cwd=str(repo), home=str(home))
        assert ret == 0

        captured = capsys.readouterr()
        assert captured.out == ('added dotfiles/plain/common/file\n'
                                'added dotfiles/plain/common/file2\n'
                                'modified filelist\n\n'
                                'plain-plugin updates not yet in repo:\n'
                                f'modified {home / "file"}\n')
Example #14
0
    def test_add_separate_cats(self, tmp_path):
        home, repo = self.setup_repo(tmp_path)
        filelist = repo / "filelist"

        (home / "foo").touch()
        filelist.write_text("foo:asd,common")
        main(args=['update'], cwd=str(repo), home=str(home))

        assert (home / "foo").is_symlink()
        assert (home / "foo").exists()
        assert (home / "foo").resolve().parent.match("*/asd")

        filelist.write_text("foo:asd\nfoo")
        main(args=['update'], cwd=str(repo), home=str(home))

        assert (home / "foo").is_symlink()
        assert (home / "foo").exists()
        assert (home / "foo").resolve().parent.match("*/common")

        assert (repo / "dotfiles" / "plain" / "asd" / "foo").exists()
        assert not (repo / "dotfiles" / "plain" / "asd" / "foo").is_symlink()
Example #15
0
    def test_add_to_flist(self, tmp_path):
        home, repo = self.setup_repo(tmp_path)
        filelist = repo / "filelist"

        filelist.write_text("foo")
        main(args=['update'], cwd=str(repo), home=str(home))
        assert not (repo / "dotfiles").is_dir()

        (home / "foo").touch()
        main(args=['update'], cwd=str(repo), home=str(home))
        assert (repo / "dotfiles").is_dir()
        assert (home / "foo").is_symlink()
        assert (home / "foo").exists()

        filelist.write_text("foo\nbar")
        main(args=['update'], cwd=str(repo), home=str(home))
        assert (repo / "dotfiles").is_dir()

        (home / "bar").touch()
        main(args=['update'], cwd=str(repo), home=str(home))
        assert (home / "foo").is_symlink()
        assert (home / "foo").exists()
        assert (home / "bar").is_symlink()
        assert (home / "bar").exists()
Example #16
0
 def test_commit_nochanges(self, tmp_path, caplog):
     home, repo = self.setup_repo(tmp_path, '')
     assert main(args=['commit'], cwd=str(repo), home=str(home)) == 0
     assert 'no changes detected' in caplog.text