Renamed "verify" functions to "validate".
Another idea for defining the fields in records would be to create a class method that would instantiate the individual fields at instance creation rather than during class definition. This would use less memory when there are no Record objects being used. Storing each Field after it's instantiated into a List, as well as a Dict would remove the necessity for counting the Field instantiation order, since the List would hold them in their proper order.
This commit is contained in:
parent
ea492c2f56
commit
7772ec679f
2 changed files with 12 additions and 9 deletions
|
@ -42,7 +42,7 @@ def test_record_order():
|
|||
record.TotalRecord(),
|
||||
record.FinalRecord(),
|
||||
]
|
||||
verify_record_order(records)
|
||||
validate_record_order(records)
|
||||
|
||||
|
||||
def test_load(fp):
|
||||
|
@ -85,7 +85,7 @@ def dumps(records):
|
|||
# THIS WAS IN CONTROLLER, BUT UNLESS WE
|
||||
# REALLY NEED A CONTROLLER CLASS, IT'S SIMPLER
|
||||
# TO JUST KEEP IT IN HERE.
|
||||
def verify_required_records(records):
|
||||
def validate_required_records(records):
|
||||
types = [rec.__class__.__name__ for rec in records]
|
||||
req_types = []
|
||||
|
||||
|
@ -101,7 +101,7 @@ def verify_required_records(records):
|
|||
else:
|
||||
req_types.remove(req)
|
||||
|
||||
def verify_record_order(records):
|
||||
def validate_record_order(records):
|
||||
import record
|
||||
from fields import ValidationError
|
||||
|
||||
|
@ -142,9 +142,9 @@ def verify_record_order(records):
|
|||
if len(filter(lambda x:isinstance(x, record.FinalRecord), records)) != 1:
|
||||
raise ValidationError("Incorrect number of FinalRecords")
|
||||
|
||||
def verify_records(records):
|
||||
verify_required_records(records)
|
||||
verify_record_order(records)
|
||||
def validate_records(records):
|
||||
validate_required_records(records)
|
||||
validate_record_order(records)
|
||||
|
||||
def test_unique_fields():
|
||||
r1 = EmployeeWageRecord()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from fields import Field
|
||||
from fields import Field, ValidationError
|
||||
import copy
|
||||
import pdb
|
||||
|
||||
|
@ -51,7 +51,10 @@ class Model(object):
|
|||
custom_validator(f)
|
||||
|
||||
def output(self):
|
||||
return ''.join([self.record_identifier] + [field.get_data() for field in self.get_sorted_fields()])
|
||||
result = ''.join([self.record_identifier] + [field.get_data() for field in self.get_sorted_fields()])
|
||||
if len(result) != 512:
|
||||
raise ValidationError("Record result length not equal to 512 bytes")
|
||||
return result
|
||||
|
||||
def read(self, fp):
|
||||
for field in self.get_sorted_fields():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue