Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonderfecht committed Jul 24, 2015
1 parent 2c42cc9 commit 434d355
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions python/Rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def __init__(self, schema, rx):
self.alts = [ rx.make_schema(alt) for alt in schema['of'] ]

def validate(self, value, name='object'):
if self.alts is None:
return
error_messages = []
for schema in self.alts:
try:
Expand Down Expand Up @@ -273,7 +275,7 @@ def validate(self, value, name='object'):
if self.range and not self.range(value):
raise SchemaMismatch(name+' not in range')

if self.value and value != self.value:
if self.value is not None and value != self.value:
raise SchemaMismatch(name+' must be '+str(self.value))

class MapType(_CoreType):
Expand All @@ -295,6 +297,8 @@ def validate(self, value, name='object'):
if not isinstance(value, dict):
raise SchemaMismatch(name+' must be a map')

error_messages = []

for key, val in value.items():
try:
self.value_schema.validate(val, key)
Expand Down Expand Up @@ -344,7 +348,7 @@ def validate(self, value, name='object'):
if self.range and not self.range(value):
raise SchemaMismatch(name+' not in range')

if self.value and value != self.value:
if self.value is not None and value != self.value:
raise SchemaMismatch(name+' must be '+str(self.value))

class OneType(_CoreType):
Expand Down Expand Up @@ -409,7 +413,7 @@ def validate(self, value, name='object'):
if unknown:
rest = {key: value[key] for key in unknown}
try:
if not self.rest_schema.check(rest): return False
self.rest_schema.validate(rest, name)
except SchemaMismatch as e:
error_messages.append(str(e))

Expand Down Expand Up @@ -449,7 +453,7 @@ def validate(self, value, name='object'):

error_messages = []

for i, (schema, item) in enumerate(zip(self.content.schema, value)):
for i, (schema, item) in enumerate(zip(self.content_schema, value)):
try:
schema.validate(item, 'item '+str(i))
except SchemaMismatch as e:
Expand Down
11 changes: 6 additions & 5 deletions python/rx-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import json
import re
import pdb
import os

plan(None)

os.chdir('..')
rx = Rx.Factory({ "register_core_types": True });

isa_ok(rx, Rx.Factory)
Expand Down Expand Up @@ -88,6 +89,7 @@ def normalize(entries, test_data):
try:
schema = rx.make_schema(schema_test_spec["schema"])
except Rx.SchemaError as e:
#pdb.set_trace()
if schema_test_spec.get("invalid", False):
ok(1, "BAD SCHEMA: schemata %s" % schema_name)
continue
Expand All @@ -112,10 +114,9 @@ def normalize(entries, test_data):

desc = "%s/%s against %s" % (source, entry, schema_name)

if ('pass' if result else 'fail') != pf:
pdb.set_trace()

if pf == 'pass':
ok(result, "VALID : %s" % desc)
if not result: pdb.set_trace()
else:
ok(not(result), "INVALID: %s" % desc)
ok(not result, "INVALID: %s" % desc)
if result: pdb.set_trace()

0 comments on commit 434d355

Please sign in to comment.