diff --git a/owners.py b/owners.py index 18dd311537..5aabb60077 100644 --- a/owners.py +++ b/owners.py @@ -17,9 +17,10 @@ BASIC_EMAIL_REGEXP = r'^[\w\-\+\%\.]+\@[\w\-\+\%\.]+$' def _assert_is_collection(obj): - assert (isinstance(obj, collections.Iterable) and - isinstance(obj, collections.Sized) and - not isinstance(obj, basestring)) + assert not isinstance(obj, basestring) + if hasattr(collections, 'Iterable') and hasattr(collections, 'Sized'): + assert (isinstance(obj, collections.Iterable) and + isinstance(obj, collections.Sized)) class SyntaxErrorInOwnersFile(Exception): diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py index 1ac7a5e202..92029bc60f 100755 --- a/tests/owners_unittest.py +++ b/tests/owners_unittest.py @@ -109,8 +109,9 @@ class OwnersDatabaseTest(unittest.TestCase): # Check that we're passed in a sequence that isn't a string. self.assertRaises(AssertionError, db.files_not_covered_by, 'foo', []) - self.assertRaises(AssertionError, db.files_not_covered_by, - (f for f in ['x', 'y']), []) + if hasattr(owners.collections, 'Iterable'): + self.assertRaises(AssertionError, db.files_not_covered_by, + (f for f in ['x', 'y']), []) # Check that the files are under the root. db.root = '/checkout' @@ -139,7 +140,9 @@ class OwnersDatabaseTest(unittest.TestCase): # Check that we're passed in a sequence that isn't a string. self.assertRaises(AssertionError, db.reviewers_for, 'foo') - self.assertRaises(AssertionError, db.reviewers_for, (f for f in ['x', 'y'])) + if hasattr(owners.collections, 'Iterable'): + self.assertRaises(AssertionError, db.reviewers_for, + (f for f in ['x', 'y'])) # Check that the files are under the root. db.root = '/checkout'