run through 2to3
This commit is contained in:
parent
961aedc0ae
commit
16bf2c41d0
7 changed files with 82 additions and 80 deletions
|
@ -1,5 +1,6 @@
|
|||
from record import *
|
||||
from reader import RecordReader
|
||||
from .record import *
|
||||
from .reader import RecordReader
|
||||
import collections
|
||||
|
||||
VERSION = (0, 2012, 0)
|
||||
|
||||
|
@ -16,33 +17,33 @@ RECORD_TYPES = [
|
|||
]
|
||||
|
||||
def test():
|
||||
import record, model
|
||||
from fields import ValidationError
|
||||
from . import record, model
|
||||
from .fields import ValidationError
|
||||
for rname in RECORD_TYPES:
|
||||
inst = record.__dict__[rname]()
|
||||
try:
|
||||
output_length = len(inst.output())
|
||||
except ValidationError, e:
|
||||
print e.msg, type(inst), inst.record_identifier
|
||||
except ValidationError as e:
|
||||
print(e.msg, type(inst), inst.record_identifier)
|
||||
continue
|
||||
|
||||
print type(inst), inst.record_identifier, output_length
|
||||
print(type(inst), inst.record_identifier, output_length)
|
||||
|
||||
|
||||
def test_dump():
|
||||
import record, StringIO
|
||||
import record, io
|
||||
records = [
|
||||
record.SubmitterRecord(),
|
||||
record.EmployerRecord(),
|
||||
record.EmployeeWageRecord(),
|
||||
]
|
||||
out = StringIO.StringIO()
|
||||
out = io.StringIO()
|
||||
dump(records, out)
|
||||
return out
|
||||
|
||||
|
||||
def test_record_order():
|
||||
import record
|
||||
from . import record
|
||||
records = [
|
||||
record.SubmitterRecord(),
|
||||
record.EmployerRecord(),
|
||||
|
@ -58,7 +59,7 @@ def test_load(fp):
|
|||
|
||||
def load(fp):
|
||||
# BUILD LIST OF RECORD TYPES
|
||||
import record
|
||||
from . import record
|
||||
types = {}
|
||||
for r in RECORD_TYPES:
|
||||
klass = record.__dict__[r]
|
||||
|
@ -73,8 +74,8 @@ def load(fp):
|
|||
yield record
|
||||
|
||||
def loads(s):
|
||||
import StringIO
|
||||
fp = StringIO.StringIO(s)
|
||||
import io
|
||||
fp = io.StringIO(s)
|
||||
return load(fp)
|
||||
|
||||
|
||||
|
@ -83,21 +84,21 @@ def dump(records, fp):
|
|||
fp.write(r.output())
|
||||
|
||||
def dumps(records):
|
||||
import StringIO
|
||||
fp = StringIO.StringIO()
|
||||
import io
|
||||
fp = io.StringIO()
|
||||
dump(records, fp)
|
||||
fp.seek(0)
|
||||
return fp.read()
|
||||
|
||||
def json_dumps(records):
|
||||
import json
|
||||
import model
|
||||
from . import model
|
||||
import decimal
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
|
||||
def default(self, o):
|
||||
if hasattr(o, 'toJSON') and callable(getattr(o, 'toJSON')):
|
||||
if hasattr(o, 'toJSON') and isinstance(getattr(o, 'toJSON'), collections.Callable):
|
||||
return o.toJSON()
|
||||
|
||||
elif isinstance(o, decimal.Decimal):
|
||||
|
@ -110,7 +111,7 @@ def json_dumps(records):
|
|||
|
||||
def json_loads(s, record_classes):
|
||||
import json
|
||||
import fields
|
||||
from . import fields
|
||||
import decimal
|
||||
import re
|
||||
|
||||
|
@ -151,14 +152,14 @@ def validate_required_records(records):
|
|||
while req_types:
|
||||
req = req_types[0]
|
||||
if req not in types:
|
||||
from fields import ValidationError
|
||||
from .fields import ValidationError
|
||||
raise ValidationError("Record set missing required record: %s" % req)
|
||||
else:
|
||||
req_types.remove(req)
|
||||
|
||||
def validate_record_order(records):
|
||||
import record
|
||||
from fields import ValidationError
|
||||
from . import record
|
||||
from .fields import ValidationError
|
||||
|
||||
# 1st record must be SubmitterRecord
|
||||
if not isinstance(records[0], record.SubmitterRecord):
|
||||
|
@ -178,10 +179,10 @@ def validate_record_order(records):
|
|||
if not isinstance(records[i+1], record.EmployeeWageRecord):
|
||||
raise ValidationError("All EmployerRecords must be followed by an EmployeeWageRecord")
|
||||
|
||||
num_ro_records = len(filter(lambda x:isinstance(x, record.OptionalEmployeeWageRecord), records))
|
||||
num_ru_records = len(filter(lambda x:isinstance(x, record.OptionalTotalRecord), records))
|
||||
num_employer_records = len(filter(lambda x:isinstance(x, record.EmployerRecord), records))
|
||||
num_total_records = len(filter(lambda x: isinstance(x, record.TotalRecord), records))
|
||||
num_ro_records = len([x for x in records if isinstance(x, record.OptionalEmployeeWageRecord)])
|
||||
num_ru_records = len([x for x in records if isinstance(x, record.OptionalTotalRecord)])
|
||||
num_employer_records = len([x for x in records if isinstance(x, record.EmployerRecord)])
|
||||
num_total_records = len([x for x in records if isinstance(x, record.TotalRecord)])
|
||||
|
||||
# a TotalRecord is required for each instance of an EmployeeRecord
|
||||
if num_total_records != num_employer_records:
|
||||
|
@ -194,7 +195,7 @@ def validate_record_order(records):
|
|||
num_ro_records, num_ru_records))
|
||||
|
||||
# FinalRecord - Must appear only once on each file.
|
||||
if len(filter(lambda x:isinstance(x, record.FinalRecord), records)) != 1:
|
||||
if len([x for x in records if isinstance(x, record.FinalRecord)]) != 1:
|
||||
raise ValidationError("Incorrect number of FinalRecords")
|
||||
|
||||
def validate_records(records):
|
||||
|
@ -207,8 +208,8 @@ def test_unique_fields():
|
|||
r1.employee_first_name.value = "John Johnson"
|
||||
|
||||
r2 = EmployeeWageRecord()
|
||||
print 'r1:', r1.employee_first_name.value, r1.employee_first_name, r1.employee_first_name.creation_counter
|
||||
print 'r2:', r2.employee_first_name.value, r2.employee_first_name, r2.employee_first_name.creation_counter
|
||||
print('r1:', r1.employee_first_name.value, r1.employee_first_name, r1.employee_first_name.creation_counter)
|
||||
print('r2:', r2.employee_first_name.value, r2.employee_first_name, r2.employee_first_name.creation_counter)
|
||||
|
||||
if r1.employee_first_name.value == r2.employee_first_name.value:
|
||||
raise ValidationError("Horrible problem involving shared values across records")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue