def test_phony_hash(tmpdir): """Make a missing file phony and ensure stale by stale child (that had old hash).""" os.chdir(tmpdir) all = '1 2 3 4 5 6 7'.split() fill(all, '') db = dagger.hashdb('tmp.db') for f in all: db.update(f) db.export() fill(['4'], 'test') d = dagger.dagger('tmp.db') d.hashall = True d.add('1', ['2', '3']) d.add('3', ['4', '5']) d.add('6', ['3', '7']) d.phony('6') d.run() truth = {'1': 1, '2': 0, '3': 1, '4': 1, '5': 0, '6': 1, '7': 0} states1 = stale_dict(d, all) assert states1 == truth
def test_phony_hash(): """Make a missing file phony and ensure stale by stale child (that had old hash).""" import dagger all = '1 2 3 4 5 6 7'.split() fill(all,'') db = dagger.hashdb('tmp.db') for f in all: db.update(f) db.export() fill(['4'], 'test') d = dagger.dagger('tmp.db') d.hashall = True d.add('1', ['2','3']) d.add('3', ['4','5']) d.add('6', ['3','7']) d.phony('6') d.run() truth = {'1':1, '2':0, '3':1, '4':1, '5':0, '6':1, '7':0} states1 = stale_dict(d, all) if states1 != truth: print('states1 =',states1,'<>\ntruth =',truth,'\n') return False return 1
def test_hash(): """Check stale when file hashes change.""" import dagger all = '1 2 3 4 5 6 7'.split() fill(all,'') db = dagger.hashdb('tmp.db') for f in all: db.update(f) db.export() fill(['5'], 'test') d = dagger.dagger('tmp.db') d.hashall = True d.add('1', ['2','3']) d.add('3', ['4','5']) d.add('6', ['3','7']) d.run() truth = {'1':1, '2':0, '3':1, '4':0, '5':1, '6':1, '7':0} states1 = stale_dict(d, all) if states1 != truth: print('states1 =',states1,'<>\ntruth =',truth,'\n') return False return 1
def test_load(tmpdir): test_export(tmpdir) d = dagger.hashdb('tmp.db') d.load() assert d.db assert len(d.db['tmp1']) > 1 assert d.db['tmp1'] == d.db['tmp2'] assert d.db['tmp1'] != d.db['tmp3']
def test_export(): import os,dagger os.system('echo 1 > tmp1') os.system('echo 1 > tmp2') os.system('echo 2 > tmp3') d = dagger.hashdb('tmp.db') d.update('tmp1') d.update('tmp2') d.update('tmp3') d.export() del d lut = dict([x.split(',') for x in open('tmp.db').readlines()]) return lut and len(lut['tmp1']) > 1 and lut['tmp1'] == lut['tmp2'] and lut['tmp1'] != lut['tmp3']
def test_export(tmpdir): os.chdir(tmpdir) os.system('echo 1 > tmp1') os.system('echo 1 > tmp2') os.system('echo 2 > tmp3') d = dagger.hashdb('tmp.db') d.update('tmp1') d.update('tmp2') d.update('tmp3') d.export() del d lut = dict([x.split(',') for x in open('tmp.db').readlines()]) assert lut assert len(lut['tmp1']) > 1 assert lut['tmp1'] == lut['tmp2'] assert lut['tmp1'] != lut['tmp3']
def test_hash(tmpdir): """Check stale when file hashes change.""" os.chdir(tmpdir) all = '1 2 3 4 5 6 7'.split() fill(all, '') db = dagger.hashdb('tmp.db') for f in all: db.update(f) db.export() fill(['5'], 'test') d = dagger.dagger('tmp.db') d.hashall = True d.add('1', ['2', '3']) d.add('3', ['4', '5']) d.add('6', ['3', '7']) d.run() truth = {'1': 1, '2': 0, '3': 1, '4': 0, '5': 1, '6': 1, '7': 0} states1 = stale_dict(d, all) assert states1 == truth
def test_load_missing(): import os,dagger d = dagger.hashdb() d.load(silent=True) return 1
def test_load(): import os,dagger d = dagger.hashdb('tmp.db') d.load() return d.db and len(d.db['tmp1']) > 1 and d.db['tmp1'] == d.db['tmp2'] and d.db['tmp1'] != d.db['tmp3']
def test_update(): import os,dagger os.system('touch tmp') d = dagger.hashdb() d.update('tmp') return d.get('tmp')
def test_get_missing(): import os,dagger d = dagger.hashdb() return not d.get('tmp')
def test_update(tmpdir): os.chdir(tmpdir) os.system('touch tmp') d = dagger.hashdb() d.update('tmp') assert d.get('tmp')
def test_get_missing(): d = dagger.hashdb() assert not d.get('tmp')
def test_load_missing(): d = dagger.hashdb() d.load()