Skip to content

Commit

Permalink
Fix unit tests by fixing tag validation bug they were detecting. Upda…
Browse files Browse the repository at this point in the history
…te unit tests to reflect new data types.
  • Loading branch information
Jonathan Wedell authored and Jonathan Wedell committed May 14, 2018
1 parent fe2d534 commit 223a39a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pynmrstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def __init__(self, schema_file=None):

csv_reader_instance = csv_reader(types_file)
for item in csv_reader_instance:
self.data_types[item[0]] = item[1]
self.data_types[item[0]] = "^" + item[1] + "$"

def __repr__(self):
"""Return how we can be initialized."""
Expand Down Expand Up @@ -2550,7 +2550,7 @@ def compare(self, other):
for tag in self.tags:
other_tag = other.get_tag(tag[0])

if other_tag == []:
if not other_tag:
diffs.append("\tNo tag with name '%s.%s' in compared "
"entry." % (self.tag_prefix, tag[0]))
continue
Expand Down Expand Up @@ -3779,6 +3779,8 @@ def validate(self, validate_schema=True, schema=None,
for row_num, row in enumerate(self.data):
for pos, datum in enumerate(row):
line_no = str(row_num) + " tag " + str(pos) + " of loop"
if datum == "a":
pass
errors.extend(my_schema.val_type(self.category + "." +
self.tags[pos], datum,
category=category,
Expand Down
7 changes: 3 additions & 4 deletions unit_tests/bmrb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ def test_Schema(self):
self.assertEqual(default.headers, ['Dictionary sequence', 'SFCategory', 'ADIT category mandatory', 'ADIT category view type', 'ADIT super category ID', 'ADIT super category', 'ADIT category group ID', 'ADIT category view name', 'Tag', 'BMRB current', 'Query prompt', 'Query interface', 'SG Mandatory', '', 'ADIT exists', 'User full view', 'Metabolomics', 'Metabolites', 'SENCI', 'Fragment library', 'Item enumerated', 'Item enumeration closed', 'Enum parent SFcategory', 'Enum parent tag', 'Derived enumeration mantable', 'Derived enumeration', 'ADIT item view name', 'Data Type', 'Nullable', 'Non-public', 'ManDBTableName', 'ManDBColumnName', 'Row Index Key', 'Saveframe ID tag', 'Source Key', 'Table Primary Key', 'Foreign Key Group', 'Foreign Table', 'Foreign Column', 'Secondary index', 'Sub category', 'Units', 'Loopflag', 'Seq', 'Adit initial rows', 'Enumeration ties', 'Mandatory code overides', 'Overide value', 'Overide view value', 'ADIT auto insert', 'Example', 'Prompt', 'Interface', 'bmrbPdbMatchID', 'bmrbPdbTransFunc', 'STAR flag', 'DB flag', 'SfNamelFlg', 'Sf category flag', 'Sf pointer', 'Natural primary key', 'Natural foreign key', 'Redundant keys', 'Parent tag', 'public', 'internal', 'small molecule', 'small molecule', 'metabolomics', 'Entry completeness', 'Overide public', 'internal', 'small molecule', 'small molecule', 'metabolomic', 'metabolomic', 'default value', 'Adit form code', 'Tag category', 'Tag field', 'Local key', 'Datum count flag', 'NEF equivalent', 'mmCIF equivalent', 'Meta data', 'Tag delete', 'BMRB data type', 'STAR vs Curated DB', 'Key group', 'Reference table', 'Reference column', 'Dictionary description', 'variableTypeMatch', 'entryIdFlg', 'outputMapExistsFlg', 'lclSfIdFlg', 'Met ADIT category view name', 'Met Example', 'Met Prompt', 'Met Description', 'SM Struct ADIT-NMR category view name', 'SM Struct Example', 'SM Struct Prompt', 'SM Struct Description', 'Met default value', 'SM default value'] )

self.assertEqual(default.val_type("_Entity.ID", 1), [])
self.assertEqual(default.val_type("_Entity.ID", "test"), ["Value does not match specification: '_Entity.ID':'test' on line 'None'.\n Type specified: int\n Regular expression for type: '-?[0-9]+'"])
self.assertEqual(default.val_type("_Entity.ID", "test"), ["Value does not match specification: '_Entity.ID':'test' on line 'None'.\n Type specified: int\n Regular expression for type: '^(?:-?[0-9]*)?$'"])
self.assertEqual(default.val_type("_Atom_chem_shift.Val", float(1.2)), [])
self.assertEqual(default.val_type("_Atom_chem_shift.Val", "invalid"), ["Value does not match specification: '_Atom_chem_shift.Val':'invalid' on line 'None'.\n Type specified: float\n Regular expression for type: '-?(([0-9]+)[.]?|([0-9]*[.][0-9]+))([(][0-9]+[)])?([eE][+-]?[0-9]+)?'"])
self.assertEqual(default.val_type("_Atom_chem_shift.Val", "invalid"), ["Value does not match specification: '_Atom_chem_shift.Val':'invalid' on line 'None'.\n Type specified: float\n Regular expression for type: '^(?:-?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)?$'"])

self.assertEqual(default.val_type("_Entry.ID", "this should be far too long - much too long"), ["Length of '43' is too long for CHAR(12): '_Entry.ID':'this should be far too long - much too long' on line 'None'."])
self.assertEqual(default.val_type("_Assembly.Ambiguous_chem_comp_sites", "this should be far too long - much too long"), ["Length of '43' is too long for VARCHAR(3): '_Assembly.Ambiguous_chem_comp_sites':'this should be far too long - much too long' on line 'None'."])

def test_entry_delitem(self):
del(self.entry[0])
Expand Down Expand Up @@ -193,7 +192,7 @@ def test_validate(self):
validation = [u"Value cannot be NULL but is: '_Chem_comp.Provenance':'.' on line 'None'."]
self.assertEqual(self.entry.validate(), validation)
self.entry[-1][-1][0][0] = 'a'
validation.append("Value does not match specification: '_Atom_chem_shift.ID':'a' on line '0 tag 0 of loop'.\n Type specified: int\n Regular expression for type: '-?[0-9]+'")
validation.append("Value does not match specification: '_Atom_chem_shift.ID':'a' on line '0 tag 0 of loop'.\n Type specified: int\n Regular expression for type: '^(?:-?[0-9]*)?$'")
self.assertEqual(self.entry.validate(), validation)
self.entry[-1][-1][0][0] = '1'

Expand Down

0 comments on commit 223a39a

Please sign in to comment.