def test_unexpected_exception_during_fingerprint_load(): """Check that we catch all exceptions raised during fingerprint load. """ bs = BuildSpace(root_dir=os.getcwd(), primitive='build') bs.create() fingerprint_filename = bs.fingerprint_filename(kind='build') # Scenario: The fingerprint file is actually not a file... mkdir(fingerprint_filename) fp = bs.load_fingerprint(kind='build') assert fp == Fingerprint() os.rmdir(fingerprint_filename) # Scenario: The fingerprint file is not readable (lack of permissions # in this case). # # Note that we do not have an easy way to remove read permission # to a file when on Windows, so we simply avoid that test when # on that platform. This test exercises the same code as in # the previous scenario, so this is not a big loss. if sys.platform != 'win32': ref_fp = Fingerprint() ref_fp.add('key1', 'val1') bs.save_fingerprint(kind='build', fingerprint=ref_fp) os.chmod(fingerprint_filename, 0) fp = bs.load_fingerprint(kind='build') assert fp == Fingerprint() os.chmod(fingerprint_filename, 0o600) os.remove(fingerprint_filename)
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(): """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) 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(bs.fingerprint_filename('build'), '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