def test_commit_signature(fake_vcs, fake_user_config): stage_signature(fake_vcs, 'dummy') committed_path = _get_committed_history_path(fake_vcs) staged_path = _get_staged_history_path(fake_vcs) # test unstaged with pytest.raises(NotStagedError): commit_signature(fake_vcs, fake_user_config, 'signature1') # test staged stage_signature(fake_vcs, 'signature1') commit_signature(fake_vcs, fake_user_config, 'signature1') with open(committed_path, 'r') as f: assert f.read().strip().split() == ['signature1'] with open(staged_path, 'r') as f: assert f.read().strip().split() == ['dummy'] # test commit twice stage_signature(fake_vcs, 'signature1') with pytest.raises(AlreadyCommittedError): commit_signature(fake_vcs, fake_user_config, 'signature1') unstage_signature(fake_vcs, 'signature1') # test limit signatures = ['generatedsignature' + str(i) for i in range(fake_user_config['history_limit'])] for s in signatures: stage_signature(fake_vcs, s) commit_signature(fake_vcs, fake_user_config, s) with open(committed_path, 'r') as f: assert f.read().strip().split() == signatures with open(staged_path, 'r') as f: assert f.read().strip().split() == ['dummy']
def test_get_committed_signatures(fake_vcs): assert get_committed_signatures(fake_vcs) == [] # test committed signatures = ['signature1', 'signature2', 'signature3'] with open(_get_committed_history_path(fake_vcs), 'w') as f: f.write('\n'.join(signatures)) # order is guaranteed for committed history assert get_committed_signatures(fake_vcs) == signatures
def test_clear_history(fake_vcs): history_path = _get_committed_history_path(fake_vcs) assert not os.path.exists(history_path) clear_history(fake_vcs) # when file does not exist assert not os.path.exists(history_path) with open(history_path, 'w') as f: f.write('test') assert os.path.exists(history_path) clear_history(fake_vcs) assert not os.path.exists(history_path)
def test_commit_signature(fake_vcs, fake_user_config): stage_signature(fake_vcs, 'dummy') committed_path = _get_committed_history_path(fake_vcs) staged_path = _get_staged_history_path(fake_vcs) # test unstaged with pytest.raises(NotStagedError): commit_signature(fake_vcs, fake_user_config, 'signature1') # test staged stage_signature(fake_vcs, 'signature1') commit_signature(fake_vcs, fake_user_config, 'signature1') with open(committed_path, 'r') as f: assert f.read().strip().split() == ['signature1'] with open(staged_path, 'r') as f: assert f.read().strip().split() == ['dummy'] # test commit twice stage_signature(fake_vcs, 'signature1') with pytest.raises(AlreadyCommittedError): commit_signature(fake_vcs, fake_user_config, 'signature1') unstage_signature(fake_vcs, 'signature1') # test limit signatures = [ 'generatedsignature' + str(i) for i in range(fake_user_config['history_limit']) ] for s in signatures: stage_signature(fake_vcs, s) commit_signature(fake_vcs, fake_user_config, s) with open(committed_path, 'r') as f: assert f.read().strip().split() == signatures with open(staged_path, 'r') as f: assert f.read().strip().split() == ['dummy']