Skip to content

Commit

Permalink
BigQuery Assertion NitPicks (#24)
Browse files Browse the repository at this point in the history
* fix up assertions in BigQuery tester

* use correct base class
  • Loading branch information
zakird authored and cdzombak committed Apr 10, 2018
1 parent d5010db commit 62839e3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions zschema/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import collections
import itertools
import json
import os
import pprint
Expand Down Expand Up @@ -127,17 +129,25 @@ def assertBigQuerySchemaEqual(self, a, b):
BigQuery schemas consist of lists whose order doesn't matter, dicts,
and privimites.
"""
self.assertEquals(type(a), type(b))
if hasattr(a, '__len__') and hasattr(b, '__len__'):
self.assertEquals(len(a), len(b))
if isinstance(a, list):
for x, y in zip(sorted(a), sorted(b)):
self.assertBigQuerySchemaEqual(x, y)
elif isinstance(a, dict):
for k in a:
self.assertBigQuerySchemaEqual(a[k], b[k])
# allow python to have the first pass at deciding whether two objects
# are equal. If they aren't, apply less strict logic (e.g., allow lists
# of differing orders to be equal).
if a == b:
return
else:
self.assertEquals(a, b)
self.assertEquals(type(a), type(b))
if isinstance(a, collections.Sized) \
and isinstance(a, collections.Sized):
self.assertEquals(len(a), len(b))
if isinstance(a, list):
for x, y in itertools.izip(sorted(a), sorted(b)):
self.assertBigQuerySchemaEqual(x, y)
elif isinstance(a, dict):
for k in a:
self.assertIn(k, b)
self.assertBigQuerySchemaEqual(a[k], b[k])
else:
self.assertEquals(a, b)

def setUp(self):
self.maxDiff=10000
Expand Down

0 comments on commit 62839e3

Please sign in to comment.