def test_dirty(self, git_repo):
     ts = 1589238246
     timestamps = (
         timestamp(ts, None),
         timestamp(ts - 60, "commit message"),
         timestamp(ts - 120, "first message"),
     )
     assert get_mtime(timestamps, ignore_commits=r'ignore') == ts
 def test_first(self, git_repo):
     ts1 = 1589238000
     ts2 = 1589238180
     timestamps = (
         timestamp(ts2, "commit 2"),
         timestamp(ts1, "commit 1"),
     )
     assert get_mtime(timestamps, strategy='first') == ts1
 def test_ignore_commits(self, git_repo):
     ts1 = 1589238000
     ts2 = 1589238180
     timestamps = (
         timestamp(ts2, "[skip] commit 2"),
         timestamp(ts1, "commit 1"),
     )
     assert get_mtime(timestamps, ignore_commits=r'\[skip\]') == ts1
 def test_skip_first_commit(self, git_repo):
     ts1 = 1589238000
     ts2 = 1589238180
     timestamps = (
         timestamp(ts2, "commit 2"),
         timestamp(ts1, "commit 1"),
     )
     assert get_mtime(timestamps[1:], skip_first_commit=True) is None
     assert get_mtime(timestamps, skip_first_commit=True) == ts2
 def test_clean(self, git_repo):
     ts = 1589238186
     timestamps = (timestamp(ts, "commit message"), )
     assert get_mtime(timestamps) == ts
 def test_not_in_git(self):
     ts = 1589238006
     timestamps = (timestamp(ts, None), )
     assert get_mtime(timestamps) == ts
 def test_timestamps(self, src, ts_now):
     assert src.timestamps == (timestamp(ts_now, None), )
        return GitTimestampSource(record)

    def test_path(self, src, record):
        assert src.path == record.path + '@git-timestamp'

    def test_get_checksum(self, src, record):
        assert src.get_checksum("path_cache") \
            == _compute_checksum(src.timestamps)

    def test_timestamps(self, src, ts_now):
        assert src.timestamps == (timestamp(ts_now, None), )


@pytest.mark.parametrize(('data', 'checksum'), [
    ((), "5d460934f4a194c28ce73ada3b56d2e025d5c47c"),
    pytest.param((timestamp(1592256980, u"message"), ),
                 "db24b207c382159c97a2a6cd177c05c0f218277a",
                 marks=pytest.mark.xfail(
                     sys.version_info >= (3, ) and sys.version_info < (3, 7),
                     reason="pickle pickles integers differently in py36")),
])
def test__compute_checksum(data, checksum):
    # These checksums should be portable across platforms
    assert _compute_checksum(data) == checksum


class TestGitTimestampDescriptor(object):
    @pytest.fixture
    def desc(self):
        raw = RawValue('test', None)
        return GitTimestampDescriptor(raw)