def test_can_validate_uncommitted_changes(self): metadata = {'has_uncommitted_changes': False} v = Validator(allow_uncommitted=False) assert v.validate_consistency([metadata]) with pytest.raises(MetadataConsistencyError): metadata = {'has_uncommitted_changes': True} v.validate_consistency([metadata])
def test_timestamp_difference_within_bounds(self): v = Validator(max_age_difference=pd.Timedelta(days=10)) assert v.validate_consistency([ {'timestamp': '2017-01-01'}, {'timestamp': '2017-01-01'} ]) assert v.validate_consistency([ {'timestamp': '2017-01-01'}, {'timestamp': '2017-01-01'}, {'timestamp': '2017-01-10 12:00:01'} ])
def test_same_file_data_is_consistent(self): v = Validator(allow_different_files=False) assert v.validate_consistency([ {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-01 10:00:00'} }}, {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-01 10:00:00'} }}]) assert v.validate_consistency([ {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-01 10:00:00'} }}, {'file_data': { 'patient_height.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_list.csv': {'changed': '2017-01-01 10:00:00'} }}])
def test_different_commits_raises_error(self): v = Validator(allow_different_commits=False) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'current_commit': 'abcd'}, {'current_commit': 'efgh'}]) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'current_commit': 'abcd'}, {'current_commit': 'abcd'}, {'current_commit': 'abcde'}])
def test_timestamp_difference_out_of_bounds_raises_error(self): v = Validator(max_age_difference=pd.Timedelta(days=10)) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'timestamp': '2017-01-01'}, {'timestamp': '2017-01-21'} ]) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'timestamp': '2017-01-01'}, {'timestamp': '2017-01-02 12:00:00'}, {'timestamp': '2017-01-21'} ])
def test_same_commit_is_valid(self): v = Validator(allow_different_commits=False) assert v.validate_consistency([ {'current_commit': 'abc'}, {'current_commit': 'abc'}, {'current_commit': 'abc', 'has_uncommitted_changes': True}])
def test_some_missing_uncommitted_changes_metadata_raises_error(self): with pytest.raises(MetadataConsistencyError): v = Validator(allow_uncommitted=False) v.validate_consistency([{'has_uncommitted_changes': True}, {'has_uncommitted_changes': False}, {}])
def test_parameters_respected(self): v = Validator(allow_uncommitted=True) assert v.validate_consistency([{}]) assert v.validate_consistency([{'has_uncommitted_changes': True}]) assert v.validate_consistency([{'has_uncommitted_changes': False}])
def test_identical_metadata_is_valid(self): metadata = {'a': 1, 'b': 2} v = Validator() assert v.validate_consistency([metadata, metadata])
def test_different_file_data_raises_error(self): v = Validator(allow_different_files=False) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-01 10:00:00'} }}, {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-01 10:00:01'} }}]) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-02 10:02:00'} }}, {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-02 10:02:00'}, 'patient_height2.csv': {'changed': '2017-01-01 10:00:00'} }}]) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'file_data': {}}, {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, }}]) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-02 10:02:00'} }}, {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patientheight.csv': {'changed': '2017-01-02 10:02:00'}, }}]) with pytest.raises(MetadataConsistencyError): v.validate_consistency([ {'file_data': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-02 10:02:00'} }}, {'data_file': { 'patient_list.csv': {'changed': '2017-01-01 10:00:00'}, 'patient_height.csv': {'changed': '2017-01-02 10:02:00'}, }}])