Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created January 5, 2017 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svetlyak40wt/fbe480384e9e3f75b10523aa0b4fb6ce to your computer and use it in GitHub Desktop.
Save svetlyak40wt/fbe480384e9e3f75b10523aa0b4fb6ce to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from hamcrest import (
assert_that,
has_entries,
is_not,
)
obj = {'foo': 'bar', 'other': 'key'}
print 'Object:', obj, '\n'
try:
print 'Checking if obj has_entries(blah=\'minor\')'
assert_that(
obj,
has_entries(
blah='minor',
)
)
except AssertionError as e:
print e
try:
print 'Checking if obj is_not(has_entries(foo=\'bar\'))'
assert_that(
obj,
is_not(
has_entries(
foo='bar',
)
)
)
except AssertionError as e:
print e
Object: {'foo': 'bar', 'other': 'key'}
Checking if obj has_entries(blah='minor')
Expected: a dictionary containing {'blah': 'minor'}
but: no 'blah' key in <{'foo': 'bar', 'other': 'key'}>
Checking if obj is_not(has_entries(foo='bar'))
Expected: not a dictionary containing {'foo': 'bar'}
but: was <{'foo': 'bar', 'other': 'key'}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment