Skip to content

Commit

Permalink
new version with a new assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Jun 30, 2011
1 parent a74ea69 commit 6421d3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# sure
> Version 0.5.1
> Version 0.6
# What

Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion sure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test_sure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down

0 comments on commit 6421d3f

Please sign in to comment.