test\unit\test_archivers.py
-- -- --- --- --- --- --- --- ------- ------- ------- | import pathlib
-- -- --- --- --- --- --- --- ------- ------- ------- | from unittest.mock import patch
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import pytest
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import wily.archivers
-- -- --- --- --- --- --- --- ------- ------- ------- | import wily.config
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.archivers import git
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
01 -- --- --- --- --- --- --- ------- ------- ------- | class MockAuthor:
01 -- --- --- --- --- --- --- ------- ------- ------- | name = "Mr Test"
01 -- --- --- --- --- --- --- ------- ------- ------- | email = "test@test.com"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
01 -- --- --- --- --- --- --- ------- ------- ------- | class MockStats:
01 -- --- --- --- --- --- --- ------- ------- ------- | files = {}
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | TEST_AUTHOR = MockAuthor()
-- -- --- --- --- --- --- --- ------- ------- ------- | TEST_STATS = MockStats()
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- | class MockCommit:
02 -- --- --- --- --- --- --- ------- ------- ------- | name_rev = "1234 bbb"
02 -- --- --- --- --- --- --- ------- ------- ------- | author = TEST_AUTHOR
02 -- --- --- --- --- --- --- ------- ------- ------- | committed_date = "1/1/1990"
02 -- --- --- --- --- --- --- ------- ------- ------- | stats = TEST_STATS
02 -- --- --- --- --- --- --- ------- ------- ------- | hexsha = "123abc"
02 -- --- --- --- --- --- --- ------- ------- ------- | parents = []
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def __init__(self, message):
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | self.message = message
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
01 -- --- --- --- --- --- --- ------- ------- ------- | class MockHead:
01 -- --- --- --- --- --- --- ------- ------- ------- | is_detached = False
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- | class MockRepo:
02 -- --- --- --- --- --- --- ------- ------- ------- | active_branch = "master"
02 -- --- --- --- --- --- --- ------- ------- ------- | bare = False
02 -- --- --- --- --- --- --- ------- ------- ------- | _is_dirty = False
02 -- --- --- --- --- --- --- ------- ------- ------- | commits = [MockCommit("commit-1"), MockCommit("commit-2")]
02 -- --- --- --- --- --- --- ------- ------- ------- | head = MockHead()
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def is_dirty(self):
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | return self._is_dirty
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | def iter_commits(self, branch, max_count, reverse):
02 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert branch == self.active_branch
02 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert max_count == 99
02 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert reverse is True
02 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | return reversed(self.commits)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- | class MockGit:
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def checkout(self, *args):
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | ...
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 02 002 005 003 005 007 008 0022.46 0022.46 0001.00 | def execute(self, command, *args, **kwargs):
03 02 002 005 003 005 007 008 0022.46 0022.46 0001.00 | if command[1] == "ls-tree":
03 02 002 005 003 005 007 008 0022.46 0022.46 0001.00 | assert command[-1] == "123abc"
03 02 002 005 003 005 007 008 0022.46 0022.46 0001.00 | return "\n"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | @pytest.fixture
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def repo(tmpdir):
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | repo = MockRepo()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | tmppath = pathlib.Path(tmpdir)
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with open(tmppath / ".gitignore", "w") as test_txt:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | test_txt.write(".wily/")
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | repo.path = tmppath
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | repo.git = MockGit()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | return repo
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def test_basearchiver():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | wily.archivers.BaseArchiver(None)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_defaults():
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert wily.archivers.ARCHIVER_GIT in wily.archivers.ALL_ARCHIVERS.values()
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 004 002 004 005 006 0013.93 0006.97 0000.50 | def test_resolve_archiver():
-- -- 001 004 002 004 005 006 0013.93 0006.97 0000.50 | archiver = wily.archivers.resolve_archiver("git")
-- -- 001 004 002 004 005 006 0013.93 0006.97 0000.50 | assert archiver == wily.archivers.ARCHIVER_GIT
-- -- 001 004 002 004 005 006 0013.93 0006.97 0000.50 | assert archiver.name == "git"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def test_bad_resolve_archiver():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with pytest.raises(ValueError):
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | wily.archivers.resolve_archiver("baz")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | def test_git_init(repo):
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | with patch("wily.archivers.git.Repo", return_value=repo):
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | test_config = wily.config.DEFAULT_CONFIG
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | test_config.path = repo.path
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | archiver = git.GitArchiver(test_config)
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert archiver.repo is not None
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert archiver.config == test_config
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 | def test_git_revisions(repo, tmpdir):
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 | with patch("wily.archivers.git.Repo", return_value=repo):
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 | test_config = wily.config.DEFAULT_CONFIG
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 | test_config.path = repo.path
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 | archiver = git.GitArchiver(test_config)
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 | revisions = archiver.revisions(tmpdir, 99)
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 | assert archiver.repo is not None
-- -- --- --- --- --- --- --- ------- ------- ------- | assert archiver.config == test_config
-- -- --- --- --- --- --- --- ------- ------- ------- | assert revisions[0].key == "1234"
-- -- --- --- --- --- --- --- ------- ------- ------- | assert revisions[1].key == "1234"
-- -- --- --- --- --- --- --- ------- ------- ------- | assert revisions[0].author_name == "Mr Test"