Permalink
Browse files

Merge pull request #9 from pjdelport/python3-support

Support Python 3
  • Loading branch information...
2 parents a77c109 + 5cddaee commit 1e7befd507f79c4fe9f30fe6bdf86983e132d582 @nsigustavo committed Mar 3, 2012
Showing with 154 additions and 45 deletions.
  1. +13 −4 .gitignore
  2. +5 −0 MANIFEST.in
  3. +1 −1 ludibrio/matcher.py
  4. 0 ludibrio/specification/__init__.py
  5. +16 −0 ludibrio/specification/compat.py
  6. 0 ludibrio/specification/functional/__init__.py
  7. 0 ludibrio/specification/unit/__init__.py
  8. +5 −1 ludibrio/specification/unit/dummy.dt
  9. +6 −3 ludibrio/specification/unit/mock_msg_error.dt
  10. +4 −1 ludibrio/specification/unit/mock_unordered.dt
  11. 0 ludibrio/specification/unit/specialarguments/__init__.py
  12. +4 −1 ludibrio/specification/unit/specialarguments/contains.dt
  13. +5 −2 ludibrio/specification/unit/specialarguments/custom.dt
  14. +4 −1 ludibrio/specification/unit/specialarguments/ended_with.dt
  15. +4 −1 ludibrio/specification/unit/specialarguments/equal_to.dt
  16. +9 −3 ludibrio/specification/unit/specialarguments/equal_to_ignoring_case.dt
  17. +5 −2 ludibrio/specification/unit/specialarguments/greater_than.dt
  18. +4 −1 ludibrio/specification/unit/specialarguments/greater_than_or_equal_to.dt
  19. +6 −3 ludibrio/specification/unit/specialarguments/in_any_order.dt
  20. +5 −2 ludibrio/specification/unit/specialarguments/instance_of.dt
  21. +4 −1 ludibrio/specification/unit/specialarguments/into.dt
  22. +5 −2 ludibrio/specification/unit/specialarguments/kind_of.dt
  23. +5 −2 ludibrio/specification/unit/specialarguments/less_than.dt
  24. +4 −1 ludibrio/specification/unit/specialarguments/less_than_or_equal_to.dt
  25. +4 −1 ludibrio/specification/unit/specialarguments/like.dt
  26. +5 −2 ludibrio/specification/unit/specialarguments/specialarguments.dt
  27. +4 −1 ludibrio/specification/unit/specialarguments/started_with.dt
  28. +9 −6 ludibrio/specification/unit/spy.dt
  29. +10 −1 setup.py
  30. +8 −2 tox.ini
View
@@ -1,5 +1,14 @@
*~
-*pyc
-build
-dist
-ludibrio.egg-info
+
+# Python
+*.pyc
+/__pycache__/
+
+# setuptools / distribute
+/*.egg-info/
+/*.egg/
+/build/
+/dist/
+
+# Tox
+/.tox/
View
@@ -0,0 +1,5 @@
+include README.rst
+include tox.ini
+recursive-include docs/_sources *.txt
+recursive-include docs/_static *
+recursive-include ludibrio/specification *.dt
View
@@ -89,7 +89,7 @@ def like(string, regex):
@matcher
def equal_to_ignoring_case(x, y):
- if unicode(x, 'utf-8').lower() == unicode(y, 'utf-8').lower():
+ if unicode(x).lower() == unicode(y).lower():
return True
raise ParameterException("%r is not equal to %r ignoring case"%(x, y))
No changes.
@@ -0,0 +1,16 @@
+"""
+This module provides doctest compatibility for Python < 3.
+"""
+import sys
+
+
+if sys.version_info < (3,):
+ # Python 2 doesn't include the exception's module name in tracebacks, but
+ # Python 3 does. Simulate this for doctests by setting __name__ to the
+ # exception's fully-qualified name.
+ from ludibrio.matcher import ParameterException
+ from ludibrio.mock import MockExpectationError
+ from ludibrio.spy import SpyExpectationError
+ ParameterException.__name__ = 'ludibrio.matcher.ParameterException'
+ MockExpectationError.__name__ = 'ludibrio.mock.MockExpectationError'
+ SpyExpectationError.__name__ = 'ludibrio.spy.SpyExpectationError'
@@ -84,9 +84,13 @@ Ludibrio provides dummy objects, in order to document the intention of programme
8. 5. Should return a dictionary having dummy objects as both key and value when dict() is applied::
- >>> dict(Dummy())
+ >>> dict(Dummy()) # doctest: +SKIP
{Dummy Object: Dummy Object}
+ .. warning::
+ Using Dummy() as a dictionary key is not reliable, and will raise
+ TypeError in Python 3+.
+
8. 6. Should return its string representation::
>>> str(Dummy())
@@ -1,6 +1,9 @@
Sample of generation of error for Mock.
=======================================
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
::
>>> from ludibrio import Mock
@@ -13,7 +16,7 @@ Sample of generation of error for Mock.
...
Traceback (most recent call last):
...
- MockExpectationError: Call waiting: notcalled
+ ludibrio.mock.MockExpectationError: Call waiting: notcalled
::
@@ -26,7 +29,7 @@ Sample of generation of error for Mock.
>>> print greetings.hello('Gustavo Rezende')
Traceback (most recent call last):
...
- MockExpectationError: Mock Object received unexpected call:hello
+ ludibrio.mock.MockExpectationError: Mock Object received unexpected call:hello
::
@@ -36,4 +39,4 @@ Sample of generation of error for Mock.
>>> greetings.excuse_me(name='Diego Manhaes')
Traceback (most recent call last):
...
- MockExpectationError: Mock Object received unexpected call:excuse_me(name='Diego Manhaes')
+ ludibrio.mock.MockExpectationError: Mock Object received unexpected call:excuse_me(name='Diego Manhaes')
@@ -1,6 +1,9 @@
Sample Mock unordered
=====================
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
::
>>> from ludibrio import Mock
@@ -17,4 +20,4 @@ Sample Mock unordered
>>> print greetings.hello('Gustavo')
Traceback (most recent call last):
...
- MockExpectationError: Mock Object received unexpected call:hello
+ ludibrio.mock.MockExpectationError: Mock Object received unexpected call:hello
@@ -2,6 +2,9 @@
contains
~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Verifies if an object is contains (contain) another. The contain and include matchers do exactly the same job::
>>> from ludibrio.matcher import contains
@@ -12,5 +15,5 @@ Verifies if an object is contains (contain) another. The contain and include mat
>>> contains("Hi") == "Hello, Gustavo Rezende"
Traceback (most recent call last):
...
- ParameterException: 'Hello, Gustavo Rezende' is not contains 'Hi'
+ ludibrio.matcher.ParameterException: 'Hello, Gustavo Rezende' is not contains 'Hi'
@@ -2,6 +2,9 @@
Custom matchers
---------------
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Extending the Ludibrio with custom matchers is very easy. The function name must be the name of the matcher. The function must have 2 parameters and it must return True.
In the example, when should fails, a message can be "4 is not the square root of 9"; in another way, if the fail is in a should_not, the message could be "3 is the square root of 9", if the expectation was be_the_square_root_of(9) == 3. The example is below::
@@ -13,10 +16,10 @@ In the example, when should fails, a message can be "4 is not the square root of
... def the_square_root_of(x, y):
... import math
... if x == math.sqrt(y):return True
- ... raise ParameterException("%r is not the square root of %r"%(x, y))
+ ... raise ParameterException("%s is not the square root of %s"%(x, y))
>>> 3 == the_square_root_of(9)
True
>>> 2 == the_square_root_of(4.1)
Traceback (most recent call last):
...
- ParameterException: 2 is not the square root of 4.1...
+ ludibrio.matcher.ParameterException: 2 is not the square root of 4.1
@@ -2,6 +2,9 @@
ended_with
~~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Verifies if a string ends with a given suffix::
>>> from ludibrio.matcher import *
@@ -12,5 +15,5 @@ Verifies if a string ends with a given suffix::
>>> 'hello motto' == ended_with('world')
Traceback (most recent call last):
...
- ParameterException: 'hello motto' is not ended with 'world'
+ ludibrio.matcher.ParameterException: 'hello motto' is not ended with 'world'
@@ -2,6 +2,9 @@
equal_to
~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Checks object equality (not identity)::
@@ -12,7 +15,7 @@ Checks object equality (not identity)::
>>> 2 == equal_to(3)
Traceback (most recent call last):
...
- ParameterException: 2 is not equal to 3
+ ludibrio.matcher.ParameterException: 2 is not equal to 3
>>> name = 'dsl'
>>> name == equal_to('dsl')
True
@@ -2,6 +2,9 @@
equal_to_ignoring_case
~~~~~~~~~~~~~~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Checks equality of strings ignoring case::
>>> from ludibrio.matcher import *
@@ -18,13 +21,16 @@ Checks equality of strings ignoring case::
>>> 'I' == equal_to_ignoring_case('wi')
Traceback (most recent call last):
...
- ParameterException: 'I' is not equal to 'wi' ignoring case
+ ludibrio.matcher.ParameterException: 'I' is not equal to 'wi' ignoring case
>>> 'I' == equal_to_ignoring_case('iw')
Traceback (most recent call last):
...
- ParameterException: 'I' is not equal to 'iw' ignoring case
+ ludibrio.matcher.ParameterException: 'I' is not equal to 'iw' ignoring case
+
+ >>> u'Atenção' == equal_to_ignoring_case(u'ATENÇÃO') # doctest: +SKIP
+ True
- >>> 'Atenção' == equal_to_ignoring_case('ATENÇÃO')
+ >>> u'Aten\xe7\xe3o' == equal_to_ignoring_case(u'ATEN\xc7\xc3O')
True
@@ -2,6 +2,9 @@
greater_than
~~~~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Simply checks the given comparisons (>)::
@@ -12,11 +15,11 @@ Simply checks the given comparisons (>)::
>>> 1 == greater_than(1)
Traceback (most recent call last):
...
- ParameterException: 1 is not greater than 1
+ ludibrio.matcher.ParameterException: 1 is not greater than 1
>>> 1 == greater_than(2)
Traceback (most recent call last):
...
- ParameterException: 1 is not greater than 2
+ ludibrio.matcher.ParameterException: 1 is not greater than 2
>>> name = 'b'
>>> name == greater_than('a')
True
@@ -2,6 +2,9 @@
greater_than_or_equal_to
~~~~~~~~~~~~~~~~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Simply checks the given comparisons (>=)::
@@ -14,7 +17,7 @@ Simply checks the given comparisons (>=)::
>>> 1 == greater_than_or_equal_to(2)
Traceback (most recent call last):
...
- ParameterException: 1 is not greater than or equal to 2
+ ludibrio.matcher.ParameterException: 1 is not greater than or equal to 2
>>> name = 'b'
>>> name == greater_than_or_equal_to('a')
True
@@ -2,6 +2,9 @@
in_any_order
~~~~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Check if a iterable includes all elements of another::
>>> from ludibrio.matcher import in_any_order
@@ -12,21 +15,21 @@ Check if a iterable includes all elements of another::
>>> [1, 2, 3] == in_any_order([3, 4])
Traceback (most recent call last):
...
- ParameterException: [1, 2, 3] does not have in any order [3, 4]
+ ludibrio.matcher.ParameterException: [1, 2, 3] does not have in any order [3, 4]
>>> [1, 2, 3] == in_any_order((3, 1))
True
>>> [1, 2, 3] == in_any_order((3, 4))
Traceback (most recent call last):
...
- ParameterException: [1, 2, 3] does not have in any order (3, 4)
+ ludibrio.matcher.ParameterException: [1, 2, 3] does not have in any order (3, 4)
>>> 'should' == in_any_order(('s', 'd', 'l'))
True
>>> 'should' == in_any_order(('h', 'a'))
Traceback (most recent call last):
...
- ParameterException: 'should' does not have in any order ('h', 'a')
+ ludibrio.matcher.ParameterException: 'should' does not have in any order ('h', 'a')
@@ -2,6 +2,9 @@
instance_of
~~~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Verifies if an object is of a given type::
>>> from ludibrio.matcher import instance_of
@@ -15,8 +18,8 @@ Verifies if an object is of a given type::
>>> foo == instance_of(Foo)
True
- >>> foo == instance_of(Bar)
+ >>> foo == instance_of(Bar) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
- ParameterException: <...Foo object at ...> is not a instance of <class '...Bar'>
+ ludibrio.matcher.ParameterException: <...Foo object at ...> is not a instance of <class '...Bar'>
@@ -1,6 +1,9 @@
into
~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Verifies if an object is contained (into) another. The contain and include matchers do exactly the same job::
@@ -11,7 +14,7 @@ Verifies if an object is contained (into) another. The contain and include match
>>> into([1,2,3]) == 5
Traceback (most recent call last):
...
- ParameterException: 5 is not in [1, 2, 3]
+ ludibrio.matcher.ParameterException: 5 is not in [1, 2, 3]
>>> into([1,2,3]) == 3
True
@@ -2,6 +2,9 @@
kind_of
~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Verifies if an object is of a given type::
>>> from ludibrio.matcher import *
@@ -14,8 +17,8 @@ Verifies if an object is of a given type::
>>> foo == kind_of(Foo)
True
- >>> foo == kind_of(Bar)
+ >>> foo == kind_of(Bar) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
- ParameterException: <...Foo object at ...> is not a kind of <class '...Bar'>
+ ludibrio.matcher.ParameterException: <...Foo object at ...> is not a kind of <class '...Bar'>
@@ -2,6 +2,9 @@
less_than
~~~~~~~~~
+.. Python < 3 compatibility
+ >>> import ludibrio.specification.compat
+
Simply checks the given comparisons (<)::
>>> from ludibrio.matcher import less_than
@@ -11,11 +14,11 @@ Simply checks the given comparisons (<)::
>>> 2 == less_than(2)
Traceback (most recent call last):
...
- ParameterException: 2 is not less than 2
+ ludibrio.matcher.ParameterException: 2 is not less than 2
>>> 2 == less_than(1)
Traceback (most recent call last):
...
- ParameterException: 2 is not less than 1
+ ludibrio.matcher.ParameterException: 2 is not less than 1
>>> name = 'a'
>>> name == less_than('b')
True
Oops, something went wrong.

0 comments on commit 1e7befd

Please sign in to comment.