def test_fingerprint(): """Check dump/restore of fingerprint.""" bs = BuildSpace(root_dir=os.getcwd(), primitive='build') bs.create() fp = Fingerprint() fp.add('foo', 'bar') bs.save_fingerprint(kind='build', fingerprint=fp) # Check that the fingerprint stored on disk is equal to fp fp_checksum = bs.load_fingerprint(kind='build', sha1_only=True) assert isinstance(fp_checksum, str) loaded_fp = bs.load_fingerprint(kind='build') assert loaded_fp == fp # Now make sure that load_fingerprint does not fail when the bumped # value is corrupted with open(os.path.join(bs.meta_dir, 'build_fingerprint.yaml'), 'w') as f: f.write('[') assert bs.load_fingerprint(kind='build') == Fingerprint() # Try updating the fingerprint fp.add('key', 'value') bs.update_status( kind='build', status=ReturnValue.notready, fingerprint=fp) assert bs.get_last_status(kind='build')[0] == ReturnValue.notready loaded_fp = bs.load_fingerprint(kind='build') assert loaded_fp == fp # Updating build fingerprint also update install fingerprint loaded_fp = bs.load_fingerprint(kind='install') assert loaded_fp == fp # Now update install status bs.update_status(kind='install', status=ReturnValue.success) assert bs.get_last_status(kind='install')[0] == ReturnValue.success # build status should not be modified assert bs.get_last_status(kind='build')[0] == ReturnValue.notready
def test_fingerprint(): f1 = Fingerprint() f1.add('foo', '2') f2 = Fingerprint() f2.add('foo', '4') f12_diff = f2.compare_to(f1) assert f12_diff['new'] == set([]) assert f12_diff['updated'] == {'foo'} assert f12_diff['obsolete'] == set([]) f3 = Fingerprint() f3.add_file(__file__) f23_diff = f3.compare_to(f2) assert f23_diff['new'] == {'foo'} assert f23_diff['updated'] == set([]) assert f23_diff['obsolete'] == {os.path.basename(__file__)} assert f1.sha1() != f2.sha1() != f3.sha1() assert Env().build.os.version in str(f3) f4 = Fingerprint() f4.add_file(__file__) assert f4 == f3 f5 = Fingerprint() with pytest.raises(AnodError) as err: f5.add('f4', f4) assert 'f4 should be a string' in str(err.value)
def test_invalid_fingerprint(): """A fingerprint value should be hashable.""" with pytest.raises(AnodError): f1 = Fingerprint() f1.add('invalid', {})