Permalink
Browse files

new version with a new assertion

  • Loading branch information...
1 parent a74ea69 commit 6421d3f1858bf02b891d9991204547bb277e1a41 @gabrielfalcao committed Jun 30, 2011
Showing with 32 additions and 2 deletions.
  1. +8 −1 README.md
  2. +9 −1 sure/__init__.py
  3. +15 −0 test_sure.py
View
@@ -1,5 +1,5 @@
# sure
-> Version 0.5.1
+> Version 0.6
# What
@@ -26,11 +26,18 @@ a assertion toolbox that works fine with [nose](http://code.google.com/p/python-
assert that(FooBar).has("attribute_one")
assert that(FooBar).equals(FooBar)
+ # go faster
+
+ assert that(FooBar).at('attribute_one').equals('simple')
+
# and also for dictionaries
name = dict(john='doe')
assert that(name).has('john')
+ # go faster
+ assert that(name).at('john').equals('doe')
+
## strings
from sure import that
View
@@ -30,7 +30,7 @@
from pprint import pformat
from threading import local
from copy import deepcopy
-version = '0.5.1'
+version = '0.6'
def itemize_length(items):
@@ -267,6 +267,14 @@ def differs(self, dst):
def is_a(self, dst):
return isinstance(self._src, dst)
+ def at(self, key):
+ assert self.has(key)
+ if isinstance(self._src, dict):
+ return that(self._src[key])
+
+ else:
+ return that(getattr(self._src, key))
+
@explanation('%r should have %r, but have not')
def has(self, that):
return that in self
View
@@ -163,6 +163,21 @@ class Class:
assert "jo" in sure.that(name)
+def test_that_at_key_equals():
+ "sure.that().at(object).equals(object)"
+
+ class Class:
+ name = "some class"
+ Object = Class()
+ dictionary = {
+ 'name': 'John',
+ }
+
+ assert that(Class).at("name").equals('some class')
+ assert that(Object).at("name").equals('some class')
+ assert that(dictionary).at("name").equals('John')
+
+
def test_that_len_is():
"sure.that() len_is(number)"

0 comments on commit 6421d3f

Please sign in to comment.