def test_concern_level(): concern = Concern(CRITICAL, "This is a sample catastrophic failure.") assert concern.level == CRITICAL assert unicode(concern) == "This is a sample catastrophic failure." assert repr(concern) == 'Concern(CRITICAL, "This is a sample catastrophic failure.")' concern = Concern(WARNING, "This is a sample warning.") assert concern.level == WARNING assert unicode(concern) == "This is a sample warning." assert repr(concern) == 'Concern(WARNING, "This is a sample warning.")'
def test_deprecated_access(self): inst = self.Sample.from_mongo({'field': 'foo'}) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') assert inst.deprecated == 'foo' assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) assert 'via deprecated' in unicode(w[-1].message) assert 'xyzzy' in unicode(w[-1].message)
def test_concern_level(): concern = Concern(CRITICAL, "This is a sample catastrophic failure.") assert concern.level == CRITICAL assert unicode(concern) == "This is a sample catastrophic failure." assert repr( concern ) == 'Concern(CRITICAL, "This is a sample catastrophic failure.")' concern = Concern(WARNING, "This is a sample warning.") assert concern.level == WARNING assert unicode(concern) == "This is a sample warning." assert repr(concern) == 'Concern(WARNING, "This is a sample warning.")'
def test_deprecated_assignment(self): inst = self.Sample() with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') inst.deprecated = 'bar' assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) assert 'via deprecated' in unicode(w[-1].message) assert 'xyzzy' in unicode(w[-1].message) assert inst.__data__ == {'field': 'bar'}
def test_raises(self): try: self.raises.validate(None) except Concern as e: assert unicode(e) == "Oh my no." else: assert False, "Failed to raise a Concern."
def _do(self, validator): assert validator.validate([1, 27, 42]) == [1, 27, 42] try: validator.validate([1, 2, 3]) except Concern as e: assert unicode(e).startswith("Value does not contain: ") else: assert False, "Failed to raise a Concern."
def do_deprecation(value): cls, dst = value with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') cls() assert len(w) == 1, "Only one warning should be raised." assert issubclass(w[-1].category, DeprecationWarning), "Warning must be a DeprecationWarning." assert dst in unicode(w[-1].message), "Warning should mention correct class to use."
def do_deprecation(value): cls, dst = value with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') cls() assert len(w) == 1, "Only one warning should be raised." assert issubclass( w[-1].category, DeprecationWarning), "Warning must be a DeprecationWarning." assert dst in unicode( w[-1].message), "Warning should mention correct class to use."
def test_depreciated_validation_import(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') import marrow.schema.validation import marrow.schema.validation.base import marrow.schema.validation.compound import marrow.schema.validation.date import marrow.schema.validation.geo import marrow.schema.validation.network import marrow.schema.validation.pattern import marrow.schema.validation.testing import marrow.schema.validation.util assert len(w) == 1, "Only one warning should be raised." assert issubclass(w[-1].category, DeprecationWarning), "Warning must be DeprecationWarning." assert 'marrow.schema.validate' in unicode(w[-1].message), "Warning should mention correct module to import."
def test_depreciated_validation_import(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') import marrow.schema.validation import marrow.schema.validation.base import marrow.schema.validation.compound import marrow.schema.validation.date import marrow.schema.validation.geo import marrow.schema.validation.network import marrow.schema.validation.pattern import marrow.schema.validation.testing import marrow.schema.validation.util assert len(w) == 1, "Only one warning should be raised." assert issubclass( w[-1].category, DeprecationWarning), "Warning must be DeprecationWarning." assert 'marrow.schema.validate' in unicode( w[-1].message), "Warning should mention correct module to import."
def test_basic_concern_text_replacement(): concern = Concern("{who} has failed me for the {times} time.", who="Bob Dole", times="last") assert unicode(concern) == "Bob Dole has failed me for the last time."
def test_operator_invert(self): assert unicode(Sample.generic) == ~Sample.generic == 'generic'
def test_concern(self): try: self.transform('x') except Concern as e: assert self.direction in unicode(e) assert 'invalid literal' in unicode(e)
def test_native_conversion(self, Sample): inst = Sample.from_mongo({'field': '/foo'}) value = inst.field assert isinstance(value, _Path) assert unicode(value) == '/foo'
def test_basic_concern_text(): concern = Concern("This is a sample failure.") assert unicode(concern) == "This is a sample failure."
def test_basic_concern_positional_replacement(): concern = Concern("{0} has failed me for the {1} time.", "Bob Dole", "last") assert unicode(concern) == "Bob Dole has failed me for the last time."
def test_s(self): assert unicode(Sample.array.S) == 'field_name.$'
def test_embedded(self): assert unicode(Sample.embed.name) == 'embed.name'
def test_cast_string(self, Sample): inst = Sample('5832223f927cc6c1a10609f7') assert isinstance(inst.__data__['field'], oid) assert unicode(inst.field) == '5832223f927cc6c1a10609f7'