Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-python-testing-cabal-mock
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-python-testing-cabal-mock
Commits
29a7a60f
Commit
29a7a60f
authored
14 years ago
by
fuzzyman
Browse files
Options
Downloads
Patches
Plain Diff
Adding tox config file and moving with tests to not see failures under Python 2.4.
parent
25a19b86
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/changelog.txt
+1
-0
1 addition, 0 deletions
docs/changelog.txt
tests/_testwith.py
+127
-0
127 additions, 0 deletions
tests/_testwith.py
tests/testwith.py
+12
-123
12 additions, 123 deletions
tests/testwith.py
tox.ini
+4
-0
4 additions, 0 deletions
tox.ini
with
144 additions
and
123 deletions
docs/changelog.txt
+
1
−
0
View file @
29a7a60f
...
@@ -52,6 +52,7 @@ CHANGELOG
...
@@ -52,6 +52,7 @@ CHANGELOG
- pickle methods
- pickle methods
- ``__trunc__``, ``__ceil__`` and ``__floor__``
- ``__trunc__``, ``__ceil__`` and ``__floor__``
* with statement tests now skipped on Python 2.4
* Improved several docstrings and documentation
* Improved several docstrings and documentation
...
...
This diff is collapsed.
Click to expand it.
tests/_testwith.py
0 → 100644
+
127
−
0
View file @
29a7a60f
# Copyright (C) 2007-2010 Michael Foord & the mock team
# E-mail: fuzzyman AT voidspace DOT org DOT uk
# http://www.voidspace.org.uk/python/mock/
from
__future__
import
with_statement
from
tests.support
import
unittest2
from
mock
import
MagicMock
,
Mock
,
patch
,
sentinel
from
tests.support_with
import
catch_warnings
,
nested
something
=
sentinel
.
Something
something_else
=
sentinel
.
SomethingElse
class
WithTest
(
unittest2
.
TestCase
):
def
testWithStatement
(
self
):
with
patch
(
'
tests._testwith.something
'
,
sentinel
.
Something2
):
self
.
assertEqual
(
something
,
sentinel
.
Something2
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testWithStatementException
(
self
):
try
:
with
patch
(
'
tests._testwith.something
'
,
sentinel
.
Something2
):
self
.
assertEqual
(
something
,
sentinel
.
Something2
,
"
unpatched
"
)
raise
Exception
(
'
pow
'
)
except
Exception
:
pass
else
:
self
.
fail
(
"
patch swallowed exception
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testWithStatementAs
(
self
):
with
patch
(
'
tests._testwith.something
'
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
self
.
assertTrue
(
isinstance
(
mock_something
,
Mock
),
"
patching wrong type
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testPatchObjectWithStatementAs
(
self
):
mock
=
Mock
()
original
=
mock
.
something
with
patch
.
object
(
mock
,
'
something
'
):
self
.
assertNotEquals
(
mock
.
something
,
original
,
"
unpatched
"
)
self
.
assertEqual
(
mock
.
something
,
original
)
def
testWithStatementNested
(
self
):
with
catch_warnings
(
record
=
True
):
# nested is deprecated in Python 2.7
with
nested
(
patch
(
'
tests._testwith.something
'
),
patch
(
'
tests._testwith.something_else
'
))
as
(
mock_something
,
mock_something_else
):
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
self
.
assertEqual
(
something_else
,
mock_something_else
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
self
.
assertEqual
(
something_else
,
sentinel
.
SomethingElse
)
def
testWithStatementSpecified
(
self
):
with
patch
(
'
tests._testwith.something
'
,
sentinel
.
Patched
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
self
.
assertEqual
(
mock_something
,
sentinel
.
Patched
,
"
wrong patch
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testContextManagerMocking
(
self
):
mock
=
Mock
()
mock
.
__enter__
=
Mock
()
mock
.
__exit__
=
Mock
()
mock
.
__exit__
.
return_value
=
False
with
mock
as
m
:
self
.
assertEqual
(
m
,
mock
.
__enter__
.
return_value
)
mock
.
__enter__
.
assert_called_with
()
mock
.
__exit__
.
assert_called_with
(
None
,
None
,
None
)
def
testContextManagerWithMagicMock
(
self
):
mock
=
MagicMock
()
with
self
.
assertRaises
(
TypeError
):
with
mock
:
'
foo
'
+
3
mock
.
__enter__
.
assert_called_with
()
self
.
assertTrue
(
mock
.
__exit__
.
called
)
def
testWithStatementSameAttribute
(
self
):
with
patch
(
'
tests._testwith.something
'
,
sentinel
.
Patched
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
with
patch
(
'
tests._testwith.something
'
)
as
mock_again
:
self
.
assertEqual
(
something
,
mock_again
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
mock_something
,
"
restored with wrong instance
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
,
"
not restored
"
)
def
testWithStatementImbricated
(
self
):
with
patch
(
'
tests._testwith.something
'
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
with
patch
(
'
tests._testwith.something_else
'
)
as
mock_something_else
:
self
.
assertEqual
(
something_else
,
mock_something_else
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
self
.
assertEqual
(
something_else
,
sentinel
.
SomethingElse
)
def
testDictContextManager
(
self
):
foo
=
{}
with
patch
.
dict
(
foo
,
{
'
a
'
:
'
b
'
}):
self
.
assertEqual
(
foo
,
{
'
a
'
:
'
b
'
})
self
.
assertEqual
(
foo
,
{})
with
self
.
assertRaises
(
NameError
):
with
patch
.
dict
(
foo
,
{
'
a
'
:
'
b
'
}):
self
.
assertEqual
(
foo
,
{
'
a
'
:
'
b
'
})
raise
NameError
(
'
Konrad
'
)
self
.
assertEqual
(
foo
,
{})
if
__name__
==
'
__main__
'
:
unittest2
.
main
()
This diff is collapsed.
Click to expand it.
tests/testwith.py
+
12
−
123
View file @
29a7a60f
# Copyright (C) 2007-2010 Michael Foord & the mock team
import
sys
# E-mail: fuzzyman AT voidspace DOT org DOT uk
# http://www.voidspace.org.uk/python/mock/
if
sys
.
version_info
[:
2
]
>
(
2
,
5
):
from
tests._testwith
import
*
from
__future__
import
with_statement
else
:
from
tests.support
import
unittest2
from
tests.support
import
unittest2
class
TestWith
(
unittest2
.
TestCase
):
from
mock
import
MagicMock
,
Mock
,
patch
,
sentinel
@unittest2.skip
(
'
tests using with statement skipped on Python 2.4
'
)
from
tests.support_with
import
catch_warnings
,
nested
def
testWith
(
self
):
something
=
sentinel
.
Something
something_else
=
sentinel
.
SomethingElse
class
WithTest
(
unittest2
.
TestCase
):
def
testWithStatement
(
self
):
with
patch
(
'
tests.testwith.something
'
,
sentinel
.
Something2
):
self
.
assertEqual
(
something
,
sentinel
.
Something2
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testWithStatementException
(
self
):
try
:
with
patch
(
'
tests.testwith.something
'
,
sentinel
.
Something2
):
self
.
assertEqual
(
something
,
sentinel
.
Something2
,
"
unpatched
"
)
raise
Exception
(
'
pow
'
)
except
Exception
:
pass
pass
else
:
self
.
fail
(
"
patch swallowed exception
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testWithStatementAs
(
self
):
with
patch
(
'
tests.testwith.something
'
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
self
.
assertTrue
(
isinstance
(
mock_something
,
Mock
),
"
patching wrong type
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testPatchObjectWithStatementAs
(
self
):
mock
=
Mock
()
original
=
mock
.
something
with
patch
.
object
(
mock
,
'
something
'
):
self
.
assertNotEquals
(
mock
.
something
,
original
,
"
unpatched
"
)
self
.
assertEqual
(
mock
.
something
,
original
)
def
testWithStatementNested
(
self
):
with
catch_warnings
(
record
=
True
):
# nested is deprecated in Python 2.7
with
nested
(
patch
(
'
tests.testwith.something
'
),
patch
(
'
tests.testwith.something_else
'
))
as
(
mock_something
,
mock_something_else
):
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
self
.
assertEqual
(
something_else
,
mock_something_else
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
self
.
assertEqual
(
something_else
,
sentinel
.
SomethingElse
)
def
testWithStatementSpecified
(
self
):
with
patch
(
'
tests.testwith.something
'
,
sentinel
.
Patched
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
self
.
assertEqual
(
mock_something
,
sentinel
.
Patched
,
"
wrong patch
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
def
testContextManagerMocking
(
self
):
mock
=
Mock
()
mock
.
__enter__
=
Mock
()
mock
.
__exit__
=
Mock
()
mock
.
__exit__
.
return_value
=
False
with
mock
as
m
:
self
.
assertEqual
(
m
,
mock
.
__enter__
.
return_value
)
mock
.
__enter__
.
assert_called_with
()
mock
.
__exit__
.
assert_called_with
(
None
,
None
,
None
)
def
testContextManagerWithMagicMock
(
self
):
mock
=
MagicMock
()
with
self
.
assertRaises
(
TypeError
):
with
mock
:
'
foo
'
+
3
mock
.
__enter__
.
assert_called_with
()
self
.
assertTrue
(
mock
.
__exit__
.
called
)
def
testWithStatementSameAttribute
(
self
):
with
patch
(
'
tests.testwith.something
'
,
sentinel
.
Patched
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
with
patch
(
'
tests.testwith.something
'
)
as
mock_again
:
self
.
assertEqual
(
something
,
mock_again
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
mock_something
,
"
restored with wrong instance
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
,
"
not restored
"
)
def
testWithStatementImbricated
(
self
):
with
patch
(
'
tests.testwith.something
'
)
as
mock_something
:
self
.
assertEqual
(
something
,
mock_something
,
"
unpatched
"
)
with
patch
(
'
tests.testwith.something_else
'
)
as
mock_something_else
:
self
.
assertEqual
(
something_else
,
mock_something_else
,
"
unpatched
"
)
self
.
assertEqual
(
something
,
sentinel
.
Something
)
self
.
assertEqual
(
something_else
,
sentinel
.
SomethingElse
)
def
testDictContextManager
(
self
):
foo
=
{}
with
patch
.
dict
(
foo
,
{
'
a
'
:
'
b
'
}):
self
.
assertEqual
(
foo
,
{
'
a
'
:
'
b
'
})
self
.
assertEqual
(
foo
,
{})
with
self
.
assertRaises
(
NameError
):
with
patch
.
dict
(
foo
,
{
'
a
'
:
'
b
'
}):
self
.
assertEqual
(
foo
,
{
'
a
'
:
'
b
'
})
raise
NameError
(
'
Konrad
'
)
self
.
assertEqual
(
foo
,
{})
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
unittest2
.
main
()
unittest2
.
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tox.ini
0 → 100644
+
4
−
0
View file @
29a7a60f
[tox]
envlist
=
py25,py24,py26,py27
[testenv]
commands
=
unit2 discover
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment