Commit Graph

211 Commits

Author SHA1 Message Date
Free Ekanayaka 9f073b9f14 Add python 3.6 support (#36)
Add 3.6 to the list of Python versions that Travis/tox will exercise. Also, switch the pypy3 target to version 3.3 (since pkg_resources is not supported anymore on 3.2).
2017-02-22 17:27:49 +01:00
Free Ekanayaka 1b88db0c93 Add missing APIs to FakeProcess, making it match Popen (LP #1373224) 2016-11-09 09:06:37 +00:00
Robert Collins c2c28a1d47 Release 3.0.0. 2016-05-20 11:01:14 +12:00
Robert Collins 7e779dab35 Fixup the MonkeyPatch patch.
- docs.
 - cleanup patches of boundmethods to not leave cruft behind.
 - NEWS entry.

Sem-Ver: api-break
2016-05-20 10:15:41 +12:00
Robert Collins 76a127d8b3 Tweak the new tests for consistency 2016-05-19 13:21:56 +12:00
Andrew Laski 78527ff5ab Update the semantics on _fixtures.MonkeyPatch
A previous change added some logic so that when monkeypatching a
staticmethod the old_value was restored as a staticmethod. There was an
issue where the determination of whether or not a method should be
static was incorrectly checking the new function not the one to be
replaced. That caused an unintended side-effect that in order to patch
an instance method of a class the new function needed to be an instance
method of a class.

This change now reworks the semantics of MonkeyPatch to address that
issue and at the same time be explicit about how it should work in a
large number of different cases. The rule is simple and provides great
flexibility. Given a callable bar to be patched on to foo bar will be
called with any bound arguments first and then arguments of foo
appended. This is easier to visualize. Given:

class C(object):
    @classmethod
    def foo(cls, arg):
        pass

class D(object):
    @classmethod
    def bar(cls, tgtcls, arg):
        pass

def baz(cls, arg):
    pass

MonkeyPatch('...C.foo', D.bar) will result in C.foo(1) calling bar like
bar(D, C, 1) because cls on bar was already bound to D when patching.
And MonkeyPatch('...C.foo', baz) will result in baz being called with
baz(C, 1).
2016-05-19 11:51:19 +12:00
Robert Collins 8d7bde077d Avoid old versions of pbr - we require modern releases. 2016-05-18 15:47:41 +12:00
Brant Knudson 0a1518a5aa Correct MockPatchMultiple example
MockPatch was used where MockPatchMultiple was intended.
2016-04-11 10:37:10 +12:00
Brant Knudson b88db4588e Ignore .tox
.tox is created when running tox for the tests. Ignore it so
it's not accidentally checked in.
2016-04-07 16:10:12 -05:00
Robert Collins 820f12bef2 Fixup NEWS, release 2.0. 2016-04-07 13:17:52 +12:00
Andrew Laski 8c43eb9e04 MonkeyPatch staticmethod
In Python setattr(Class, name, func) automatically converts a function
into an instancemethod. To keep type(Class.func) as function,
staticmethod(func) must be applied explicitly.

This was previously fixed for Python 2 when cleaning up the patched
function but Python 3 needs the same handling.

When patching a function it was being converted to an instancemethod for
both Python 2 and 3 and this has now been fixed. This is a breaking
change as it was previously acceptable to patch a staticmethod with an
instancemethod.

The test for this case was updated to correctly check both cases. The
patched function is called as both Class.function() and
Class().function(), and then called again after the cleanup has occurred
resetting the function to its original state.  The Class().function()
check is important because the method does not become bound until the
class it is defined on is instantiated.

Sem-Ver: api-break
2016-04-07 12:33:27 +12:00
Robert Collins bdf1455631 Drop support for Python 3.2. It's history.
Sem-Ver: api-break
2016-03-24 12:42:06 +13:00
Andrew Laski 6715adb832 Fix print in README
Python 3 tests were failing on the improper usage of print in the README
examples. Print must be used as a method in Python 3.
2016-03-22 15:40:57 -04:00
Jonathan Lange bd43849d5f Add CompoundFixture
CompoundFixture combines multiple fixtures into one.
2016-02-01 09:28:32 +00:00
Robert Collins b86fef871d Tweak hacking docs. 2016-01-07 14:56:40 +13:00
Jonathan Lange 3717815436 Merge pull request #17 from jml/fix-spelling
Spelling and lint fixes
2015-11-03 12:22:27 +00:00
Jonathan Lange 1051231024 Fix "propagate" spelling everywhere 2015-11-03 12:19:40 +00:00
Jonathan Lange 1b45c9393d Missed one: propogate -> propagate 2015-11-01 09:46:06 +00:00
Jonathan Lange cc56319640 Spelling and lint fixes
"cach" -> "catch"
2015-10-31 13:22:31 +00:00
Robert Collins 6d941c657e Release 1.4 2015-10-08 14:08:25 +13:00
Robert Collins 5114f4709d Trivial pep8 fix to logger.py. 2015-10-08 14:05:39 +13:00
John L. Villalovos 67dd295694 FakeLogger: Mis-formatted log messages will raise Exception
When using the FakeLogger, have mis-formatted logging messages raise an
exception.

Normally when using the logging module, mis-formatted logging messages
will not raise an exception. Instead the exception will be printed but
not raised.

Change this behavior so that mis-formatted log messages can be caught
during unit-testing.

Closes-Bug: #1503049
Change-Id: I8d3e94d131289300ae020eb1d63306489e986335
2015-10-07 17:58:43 -07:00
Robert Collins 5522eb9263 Use mock in preference to unittest.mock.
If folk have installed both, they probably want the bugfixes from the
rolling backport vs the potentially stale Python 3.3 or 3.4 etc
version.
2015-10-08 13:13:11 +13:00
Robert Collins 20cd3e0458 Add a .travis.yml 2015-10-08 13:12:52 +13:00
Robert Collins 64dcba4234 Note how to push on releases. 2015-07-02 09:37:36 +12:00
Robert Collins 09afde5995 Release 1.3.1 2015-06-30 14:21:22 +12:00
Robert Collins b9e6bace00 Clarify the intent around _setUp. 2015-06-30 13:01:44 +12:00
Robert Collins 3f965dd8a9 Handle BaseException resource leaks as well.
The change to handle resource leaks incorrectly ignored BaseException
- e.g. KeyboardInterrupt.
2015-06-30 13:00:55 +12:00
Robert Collins 5355689a2a Release 1.3.0. 2015-06-29 14:54:02 +12:00
Robert Collins b3ef345488 Remove trailing whitespace. 2015-06-29 14:20:17 +12:00
Robert Collins 354acf568a Deal with resource leaks during setUp.
Fixture.setUp should no longer be overridden in subclasses. Instead
override _setUp. This permits the Fixture base class to detect failures
during _setUp and trigger any registered cleanups, attach any details
to the failure exception and propogate that to callers.
(Robert Collins, #1456361, #1456353)
2015-06-29 14:17:48 +12:00
Robert Collins 517fe23173 Missed NEWS entry. 2015-06-22 18:55:51 +12:00
Robert Collins 670b2a8f1d Fine tune the mock patch. 2015-06-22 12:23:44 +12:00
Julien Danjou 08be09df43 Add a new mockpatch fixture
This fixture provides an easy usage for mock (unittest.mock in
Python 3).
2015-06-22 11:52:54 +12:00
Robert Collins 8baf138829 Document where the project home and source are. 2015-06-22 11:22:23 +12:00
Robert Collins 8166645121 Ignore built things. 2015-06-22 10:43:03 +12:00
Robert Collins f7502e8261 Release 1.2.0. 2015-05-05 10:13:31 +12:00
Joshua Harlow a48a685eca Add a warnings module capture fixure
Capturing the warnings module output (which is typically used
for deprecating code or functions or modules) is quite useful and
is a frequent operation that can be required to perform. So provide
a fixture that is similar (but not the same) as the warnings
``catch_warnings`` context manager that can be used to gather all
warnings emitted and allows people to later analyze them to ensure
they are as they expect.
2015-05-04 12:47:21 -07:00
Robert Collins d47cc58afa Use universal wheels. 2015-05-04 16:08:21 +12:00
Robert Collins 18ea57d2ef Release 1.1.0 and use pbr 0.11 features. 2015-05-04 16:06:50 +12:00
Robert Collins 89856bda75 Missing NEWS entry. 2015-05-04 16:02:12 +12:00
Sean Dague 60bb0acc55 add tox.ini file
Provide tox configuration to make it easy to run tests locally against
different python environments without have to install dependencies
into the system. The default env is left at py27 only for
compatibility, however tox -e py33 and tox -e py34 will work fine with
this in place.
2015-03-27 11:29:36 +13:00
Robert Collins 31b5806880 Fixed test performance on Python 3.5.
PEP 475 led to ``time.sleep()`` not being interrupted when a received signal
handler eats the signal (rather than raising an exception). (Robert Collins)
2015-03-27 11:27:22 +13:00
Robert Collins 90ce7d729f Add NEWS for FakeLogger formatter. 2015-03-27 11:11:01 +13:00
Sean Dague bf5462fbf2 allow the specification of a custom log formatter
When working on OpenStack in tree functional test things like the
context information is extremely useful to have access to. This relies
on using custom log formatter, which currently can't be done in
fixtures.

The creates an additional optional parameter for FakeLogger to specify
this.
2015-03-26 18:06:04 -04:00
Robert Collins d5a968e349 Release 1.0.0 2014-10-28 09:24:00 +13:00
Gabi Davar 7f065a5070 remote copy/paste from another project. 2014-10-28 09:10:51 +13:00
Robert Collins 88bf7ff386 Release 0.3.17. 2014-09-26 09:09:29 +12:00
Sean Dague f556cff258 Add support for datefmt in FakeLogger
The logging fixture is extremely useful to be used a temp buffer for
collecting log messages into a buffer, and only decide if we're going
to emit them after some event in the future (like the failure or
success of some future criteria). However, in it's current form we are
not given access to the datefmt variable of the underlying Formatter,
which means we always end up with the default python time string for
%(asctime), which looks incorrectly localized many places.

This merely adds the ability to pass the datefmt param through to the
Formatter.

Signed-off-by: Sean Dague <sean@dague.net>
2014-09-26 08:48:10 +12:00
Robert Collins 797b17bc3a Migrate to git and pbr.
No functional changes.
2014-09-25 15:01:50 +12:00