def test_get_file(self, testdir, a_py): fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': -100}, checksums={'a.py': -200}) fs_data.get_file('a.py') fs_data.mtimes['a.py'] = a_py.mtime fs_data.checksums['a.py'] = 'ec1fd361d4d73353c3f65cb10b86fcea4e0d0e42'
def test_basic(self, testdir, a_py): code, checksum = read_file_with_checksum('a.py') assert checksum == 'ea4739bb5b0069cafb92af3874891898617ef590' fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': a_py.mtime()}, checksums={'a.py': checksum}) changed_files = fs_data.get_changed_files() assert changed_files == {}
def test_get_file(self, testdir): a_py = testdir.makepyfile(a=""" def test_a(): return 0 """) file_system = SourceTree(rootdir=testdir.tmpdir.strpath) module = file_system.get_file("a.py") assert module.mtime == a_py.mtime() assert module.checksum == "de226b260917867990e4fb7aac70c5d6582266d4"
def test_check_mtime(self): fs = SourceTree("") fs.cache["test_a.py"] = Module("", file_name="test_a.py", mtime=1, checksum=1000) assert check_mtime(fs, {"file_name": "test_a.py", "mtime": 1}) assert not check_mtime(fs, {"file_name": "test_a.py", "mtime": 2}) pytest.raises(Exception, check_mtime, fs, ("test_a.py", ))
def test_get_new_mtimes(self, testdir): a_py = testdir.makepyfile(a=""" def test_a(): return 0 """) fs = SourceTree(testdir.tmpdir.strpath) assert next(get_new_mtimes(fs, (("a.py", None, None, 2), ))) == ( a_py.mtime(), "de226b260917867990e4fb7aac70c5d6582266d4", 2, )
def test_mtime_filter(self): fs = SourceTree("") fs.cache["test_a.py"] = Module("", file_name="test_a.py", mtime=1, checksum=1000) record = {"file_name": "test_a.py", "mtime": 1} assert split_filter(fs, check_mtime, (record, )) == ([record], []) record2 = {"file_name": "test_a.py", "mtime": 2} assert split_filter(fs, check_mtime, (record2, )) == ([], [record2])
def test_check_checksum(self): fs = SourceTree("") fs.cache["test_a.py"] = Module("", file_name="test_a.py", mtime=1, checksum=1000) assert check_checksum(fs, {"file_name": "test_a.py", "checksum": 1000}) assert check_checksum(fs, { "file_name": "test_a.py", "checksum": 1001 }) is False assert pytest.raises(Exception, check_checksum, fs, { "file_name": "test_a.py", "bla": None })
def test_basic_checksum(self, testdir, a_py): code, checksum = read_file_with_checksum('a.py') fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': a_py.mtime()}, checksums={'a.py': checksum}) a_py.setmtime(1424880936) changed_files = fs_data.get_changed_files() assert changed_files == {} assert fs_data.mtimes['a.py'] == 1424880936 testdir.makepyfile(a=""" def test_a(): return 0 # comment """) fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': -100}, checksums={'a.py': checksum}) changed_files = fs_data.get_changed_files() assert 'a.py' in changed_files assert [type(c) for c in changed_files['a.py'].checksums] == [int, int] assert fs_data.checksums['a.py'] == 'ec1fd361d4d73353c3f65cb10b86fcea4e0d0e42'
def test_disappeared(self, testdir, a_py): fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'b.py': -100}, checksums={'b.py': -200}) fs_data.get_changed_files() pytest.raises((OSError, IOError), fs_data.get_file, 'c.py')
def test_empty_file(self, testdir): file_system = SourceTree(rootdir=testdir.tmpdir.strpath) testdir.makepyfile(__init__="") module = file_system.get_file("__init__.py") assert module.checksum == "da39a3ee5e6b4b0d3255bfef95601890afd80709"
def test_nonexistent_file(self, testdir): file_system = SourceTree(rootdir=testdir.tmpdir.strpath) assert file_system.get_file("jdslkajfnoweijflaohdnoviwn.py") is None