Projects
openEuler:Mainline
python-fixtures
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
_service:tar_scm:python-fixtures.spec
Changed
@@ -1,12 +1,10 @@ Name: python-fixtures -Version: 3.0.0 -Release: 15 +Version: 4.0.1 +Release: 1 Summary: A python contract for writing reusable state / support logic tests License: ASL 2.0 or BSD URL: https://launchpad.net/python-fixtures Source0: https://pypi.python.org/packages/source/f/fixtures/fixtures-%{version}.tar.gz -#Refer: https://github.com/testing-cabal/fixtures/commit/fe830674abd4926d96d38f9992f3e31b00cd891a -Patch0000: fix-test_monkeypatch-failed.patch BuildArch: noarch %description @@ -17,8 +15,8 @@ %package -n python3-fixtures Summary: A python3 contract for reusable state / support logic BuildArch: noarch -BuildRequires: python3-devel python3-pbr >= 0.11 python3-mock python3-testtools >= 0.9.22 -Requires: python3-testtools >= 0.9.22 python3-six +BuildRequires: python3-devel python3-pbr >= 5.7.0 python3-mock python3-testtools >= 2.5.0 +Requires: python-extras python-pbr >= 5.7.0 python3-testtools >= 2.5.0 %{?python_provide:%python_provide python3-fixtures} %description -n python3-fixtures @@ -30,20 +28,25 @@ %autosetup -n fixtures-%{version} -p1 %build +export PBR_VERSION=%{version} %py3_build %install +export PBR_VERSION=%{version} %py3_install %check %{__python3} -m testtools.run fixtures.test_suite %files -n python3-fixtures -%doc README GOALS NEWS Apache-2.0 BSD COPYING +%doc README.rst GOALS NEWS Apache-2.0 BSD COPYING %{python3_sitelib}/fixtures %{python3_sitelib}/fixtures-%{version}-py%{python3_version}.egg-info %changelog +* Thu Jul 7 2022 baizhonggui <baizhonggui@h-partners.com> - 4.0.1-1 +- Update to 4.0.1 + * Fri Apr 1 2022 caodongxia <caodongxia@huawei.com> - 3.0.0-15 - Fix test_monkeypatch failed due to python3.10
View file
_service:tar_scm:fix-test_monkeypatch-failed.patch
Deleted
@@ -1,137 +0,0 @@ -From fe830674abd4926d96d38f9992f3e31b00cd891a Mon Sep 17 00:00:00 2001 -From: Stephen Finucane <stephenfin@redhat.com> -Date: Thu, 25 Feb 2021 11:37:42 +0000 -Subject: PATCH Fix tests on Python 3.9 - -I'm not entirely sure this is correct, but it's the only thing I can -find related to changes in classmethod in Python 3.9. - -Signed-off-by: Stephen Finucane <stephenfin@redhat.com> ---- - fixtures/_fixtures/monkeypatch.py | 9 +++- - fixtures/tests/_fixtures/test_monkeypatch.py | 48 ++++++++++++++------ - 2 files changed, 42 insertions(+), 15 deletions(-) - -diff --git a/fixtures/_fixtures/monkeypatch.py b/fixtures/_fixtures/monkeypatch.py -index b5e8564..710a79c 100644 ---- a/fixtures/_fixtures/monkeypatch.py -+++ b/fixtures/_fixtures/monkeypatch.py -@@ -83,9 +83,11 @@ def _coerce_values(obj, name, new_value, sentinel): - # bound state rather than having it bound to the new object - # it has been patched onto. - captured_method = new_value -+ - @functools.wraps(old_value) - def avoid_get(*args, **kwargs): - return captured_method(*args, **kwargs) -+ - new_value = avoid_get - - return (new_value, old_value) -@@ -138,18 +140,21 @@ def _setUp(self): - __import__(location, {}, {}) - except ImportError: - pass -+ - components = location.split('.') - current = __import__(components0, {}, {}) - for component in components1:: - current = getattr(current, component) - sentinel = object() -- new_value, old_value = _coerce_values(current, attribute, -- self.new_value, sentinel) -+ new_value, old_value = _coerce_values( -+ current, attribute, self.new_value, sentinel) -+ - if self.new_value is self.delete: - if old_value is not sentinel: - delattr(current, attribute) - else: - setattr(current, attribute, new_value) -+ - if old_value is sentinel: - self.addCleanup(self._safe_delete, current, attribute) - else: -diff --git a/fixtures/tests/_fixtures/test_monkeypatch.py b/fixtures/tests/_fixtures/test_monkeypatch.py -index 6f11fab..746f6dd 100644 ---- a/fixtures/tests/_fixtures/test_monkeypatch.py -+++ b/fixtures/tests/_fixtures/test_monkeypatch.py -@@ -14,6 +14,7 @@ - # limitations under that license. - - import functools -+import sys - - import testtools - from testtools.matchers import Is -@@ -32,7 +33,7 @@ def foo_cls(cls): pass - - class D(object): - def bar(self): pass -- def bar_two_args(self, arg): -+ def bar_two_args(self, arg=None): - return (self, arg) - @classmethod - def bar_cls(cls): -@@ -188,14 +189,27 @@ def test_patch_classmethod_with_classmethod(self): - 'fixtures.tests._fixtures.test_monkeypatch.C.foo_cls', - D.bar_cls_args) - with fixture: -- cls, target_class = C.foo_cls() -- self.expectThat(cls, Is(D)) -- self.expectThat(target_class, Is(C)) -- cls, target_class = C().foo_cls() -- self.expectThat(cls, Is(D)) -- self.expectThat(target_class, Is(C)) -- self._check_restored_static_or_class_method(oldmethod, oldmethod_inst, -- C, 'foo_cls') -+ # Python 3.9 changes the behavior of the classmethod decorator so -+ # that it now honours the descriptor binding protocol 1. -+ # This means we're now going to call the monkeypatched classmethod -+ # the way we would have if it hadn't been monkeypatched: simply -+ # with the class -+ # -+ # https://bugs.python.org/issue19072 -+ if sys.version_info >= (3, 9): -+ cls, = C.foo_cls() -+ self.expectThat(cls, Is(D)) -+ cls, = C().foo_cls() -+ self.expectThat(cls, Is(D)) -+ else: -+ cls, target_class = C.foo_cls() -+ self.expectThat(cls, Is(D)) -+ self.expectThat(target_class, Is(C)) -+ cls, target_class = C().foo_cls() -+ self.expectThat(cls, Is(D)) -+ self.expectThat(target_class, Is(C)) -+ self._check_restored_static_or_class_method( -+ oldmethod, oldmethod_inst, C, 'foo_cls') - - def test_patch_classmethod_with_function(self): - oldmethod = C.foo_cls -@@ -222,12 +236,20 @@ def test_patch_classmethod_with_boundmethod(self): - with fixture: - slf, cls = C.foo_cls() - self.expectThat(slf, Is(d)) -- self.expectThat(cls, Is(C)) -+ # See note in test_patch_classmethod_with_classmethod on changes in -+ # Python 3.9 -+ if sys.version_info >= (3, 9): -+ self.expectThat(cls, Is(None)) -+ else: -+ self.expectThat(cls, Is(C)) - slf, cls = C().foo_cls() - self.expectThat(slf, Is(d)) -- self.expectThat(cls, Is(C)) -- self._check_restored_static_or_class_method(oldmethod, oldmethod_inst, -- C, 'foo_cls') -+ if sys.version_info >= (3, 9): -+ self.expectThat(cls, Is(None)) -+ else: -+ self.expectThat(cls, Is(C)) -+ self._check_restored_static_or_class_method( -+ oldmethod, oldmethod_inst, C, 'foo_cls') - - def test_patch_function_with_staticmethod(self): - oldmethod = fake_no_args - \ No newline at end of file
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="scm">git</param> <param name="url">git@gitee.com:src-openeuler/python-fixtures.git</param> - <param name="revision">eab5cccfcdd0f9fb5407463519ac738345097a7e</param> + <param name="revision">8fe5051bbf6e99a1105ae8bf9566bdac08783c79</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/.travis.yml
Deleted
@@ -1,23 +0,0 @@ -sudo: false -language: python - -python: - - "2.6" - - "2.7" - - "3.3" - - "3.4" - - "3.5" - - "pypy" - - pypy3 - - "nightly" - -install: - - pip install -U pip - - pip install -U wheel setuptools pbr - - pip install -U .docs,test - - pip list - - python --version - -script: - - make check - - rst2html.py README README.html
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/AUTHORS
Deleted
@@ -1,19 +0,0 @@ -Andrew Laski <andrew@lascii.com> -Brant Knudson <bknudson@us.ibm.com> -Clark Boylan <clark.boylan@gmail.com> -Dan Kenigsberg <danken@redhat.com> -Francesco Banconi <francesco.banconi@canonical.com> -Free Ekanayaka <free.ekanayaka@canonical.com> -Gabi Davar <grizzly.nyo@gmail.com> -Gavin Panella <gavin.panella@canonical.com> -Gavin Panella <gavin@gromper.net> -James Westby <james.westby@linaro.org> -John L. Villalovos <john.l.villalovos@intel.com> -Jonathan Lange <jml@canonical.com> -Jonathan Lange <jml@mumak.net> -Joshua Harlow <harlowja@yahoo-inc.com> -Julien Danjou <julien@danjou.info> -Martin Pool <mbp@canonical.com> -Robert Collins <robertc@robertcollins.net> -Sean Dague <sean@dague.net> -Steve Kowalik <steve.kowalik@canonical.com>
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/ChangeLog
Deleted
@@ -1,271 +0,0 @@ -CHANGES -======= - -3.0.0 ------ - -* Release 3.0.0 -* Fixup the MonkeyPatch patch -* Tweak the new tests for consistency -* Update the semantics on _fixtures.MonkeyPatch -* Avoid old versions of pbr - we require modern releases -* Correct MockPatchMultiple example -* Ignore .tox - -2.0.0 ------ - -* Fixup NEWS, release 2.0 -* MonkeyPatch staticmethod -* Drop support for Python 3.2. It's history -* Fix print in README -* Add CompoundFixture -* Tweak hacking docs -* Fix "propagate" spelling everywhere -* Missed one: propogate -> propagate -* Spelling and lint fixes - -1.4 ---- - -* Release 1.4 -* Trivial pep8 fix to logger.py -* FakeLogger: Mis-formatted log messages will raise Exception -* Use mock in preference to unittest.mock -* Add a .travis.yml -* Note how to push on releases - -1.3.1 ------ - -* Release 1.3.1 -* Clarify the intent around _setUp -* Handle BaseException resource leaks as well - -1.3.0 ------ - -* Release 1.3.0 -* Remove trailing whitespace -* Deal with resource leaks during setUp -* Missed NEWS entry -* Fine tune the mock patch -* Add a new mockpatch fixture -* Document where the project home and source are -* Ignore built things - -1.2.0 ------ - -* Release 1.2.0 -* Add a warnings module capture fixure -* Use universal wheels - -1.1.0 ------ - -* Release 1.1.0 and use pbr 0.11 features -* Missing NEWS entry -* add tox.ini file -* Fixed test performance on Python 3.5 -* Add NEWS for FakeLogger formatter -* allow the specification of a custom log formatter - -1.0.0 ------ - -* Release 1.0.0 -* remote copy/paste from another project - -0.3.17 ------- - -* Release 0.3.17 -* Add support for datefmt in FakeLogger -* Migrate to git and pbr - -0.3.16 ------- - -* 0.3.16 ~~~~~~ - -0.3.15 ------- - -* Release 0.3.15 -* * ``FakeProcess`` wait() now supports arguments added in Python 3. (Steve Kowalik) -* * ``FakeProcess`` wait() now supports arguments added in Python 3. (Steve Kowalik) -* * ``FakeProcess`` now supports kill(). (Steve Kowalik) -* * ``FakePopen`` now supports being called under a context manager (IE: with). (Steve Kowalik) -* * ``MonkeyPatch`` now preserves ``staticmethod`` functions. (Dan Kenigsberg) -* * ``FakeProcess`` now supports kill(). (Steve Kowalik) -* * ``FakePopen`` now works under a context manager itself. (Steve Kowalik, #1358085) -* MonkeyPatch staticmethod - -0.3.14 ------- - -* Release 0.3.14 -* * ``FakePopen`` can now override the returncode attribute. (Robert Collins) -* More releasing docs - -0.3.13 ------- - -* Release 0.3.13 -* * Documentation hopefully covers ``TestWithFixtures`` a little better. (Robert Collins, #1102688) -* Ignore an egg-info directory if it exists -* * ``setup.py`` now lists the ``testtools`` dependency which was missing. (Robert Collins, #1103823) -* * ``FakePopen`` now accepts all the parameters available in Python 2.7. (Robert Collins) - -0.3.12 ------- - -* 0.3.12: 0.3.11 with tests for StringStream -* Oops, setup.py wasn't 3.2 ready -* Add Python 3 Trove entry - -0.3.11 ------- - -* Release 0.3.11 -* * pydoc is recommended as a source of info about fixtures. (Robert Collins, #812845) -* * The docs for fixtures have been updated to cover the full API. (Robert Collins, #1071649) -* * ``DetailStream`` was ambiguous about whether it handled bytes or characters, which matters a lot for Python3. It now is deprecated with ByteStream and StringStream replacing it. (Robert Collins) -* Update docs -* * ``DetailStream`` was ambiguous about whether it handled bytes or characters, which matters a lot for Python3. It now is deprecated with ByteStream and StringStream replacing it. (Robert Collins) -* * ``FakeLogger`` has been split out into a ``LogHandler`` fixture that can inject arbitrary handlers, giving more flexability. (Jonathan Lange) -* Drop the MementoHandler stuff -* Rest of the tests for LogHandler -* Give up on MementoHandler, just test LogHandler instead -* Change the MementoHandler to store a dict. Start testing the logger fixture -* Make handler public -* Extract the handler managing bit of FakeLogger into its own fixture -* Add MementoHandler -* Release 0.3.10 -* * New ``DetailStream`` fixture to add file-like object content to testtools details. This allows for easy capture of sys.stdout and sys.stderr for example. (Clark Boylan) -* Document DetailStream -* * New ``DetailStream`` fixture to add file-like object content to testtools details. This allows for easy capture of sys.stdout and sys.stderr for example. (Clark Boylan) -* * Factor out new ``CallMany`` class to isolate the cleanup logic. (Robert Collins) -* Add 'join' method to TempDir -* Revert filetree patch, r54. Now in lp:treeshape -* Rename to 'join' -* Update NEWS -* Add an 'abspath' helper -* Roll back properly -* Remove filetree cruft -* Add facility to make a tree of files on a TempDir (r=lifeless) -* NEWS -* Change the API to have *args -* Move filetree tests to be against tempdir -* Remove duplicate tests -* Remove filetree -* Remove FileTree -* Make FileTree a thing on tempdir -* Rename NoHasattr to HasNoAttribute -* Spell it more simply -* Heaps more docstrings -* Integration test -* Create parent directories -* Bump the testtools dependency -* Do stuff as late as possible -* Extract out another function -* Richer error messages -* Extract the bit that normalizes the entries -* Extract normalize_shape -* Refactoring. Some comments in the tests -* Docs. Nicer directory specification -* Basic directory creation -* Start writing stuff to disk -* Initial creation of FileTree -* Add a matcher, because I can't bear to write that code again -* Clean up pyflakes -* Export TempHomeDir. Otherwise it's imported here for no reason - -0.3.9 ------ - -* Release 0.3.9 -* Include logging output in FakeLoggers' getDetails, surfacing the logs to testtools tests automatically -* Removed unused text_content import -* Updated the way the detail name is added -* Fixes from review -* Implemented FakeLogger.getDetails() -* New TempHomeDir fixture to create and activate a temporary home dir (james_w) -* Subclass TempDir rather than composing -* Fix the typo. Thanks Rob -* Remove the debugging echo -* Add a TempHomeDir fixture -
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/PKG-INFO
Deleted
@@ -1,525 +0,0 @@ -Metadata-Version: 1.1 -Name: fixtures -Version: 3.0.0 -Summary: Fixtures, reusable state for writing clean tests and more. -Home-page: https://launchpad.net/python-fixtures -Author: Robert Collins -Author-email: robertc@robertcollins.net -License: UNKNOWN -Description: ************************************************************* - fixtures: Fixtures with cleanups for testing and convenience. - ************************************************************* - - Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> - - Licensed under either the Apache License, Version 2.0 or the BSD 3-clause - license at the users choice. A copy of both licenses are available in the - project source as Apache-2.0 and BSD. You may not use this file except in - compliance with one of these two licences. - - Unless required by applicable law or agreed to in writing, software - distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - license you chose for the specific language governing permissions and - limitations under that license. - - - Fixtures defines a Python contract for reusable state / support logic, - primarily for unit testing. Helper and adaption logic is included to make it - easy to write your own fixtures using the fixtures contract. Glue code is - provided that makes using fixtures that meet the Fixtures contract in unittest - compatible test cases easy and straight forward. - - Dependencies - ============ - - * Python 2.6+, or 3.3+ - This is the base language fixtures is written in and for. - - * pbr - Used for version and release management of fixtures. - - * testtools <https://launchpad.net/testtools> 0.9.22 or newer. - testtools provides helpful glue functions for the details API used to report - information about a fixture (whether its used in a testing or production - environment). - - For use in a unit test suite using the included glue, one of: - - * Python 2.7+ - - * unittest2 - - * bzrlib.tests - - * Or any other test environment that supports TestCase.addCleanup. - - Writing your own glue code is easy, or you can simply use Fixtures directly - without any support code. - - To run the test suite for fixtures, testtools is needed. - - Why Fixtures - ============ - - Standard Python unittest.py provides no obvious method for making and reusing - state needed in a test case other than by adding a method on the test class. - This scales poorly - complex helper functions propagating up a test class - hierarchy is a regular pattern when this is done. Mocking while a great tool - doesn't itself prevent this (and helpers to mock complex things can accumulate - in the same way if placed on the test class). - - By defining a uniform contract where helpers have no dependency on the test - class we permit all the regular code hygiene activities to take place without - the distorting influence of being in a class hierarchy that is modelling an - entirely different thing - which is what helpers on a TestCase suffer from. - - About Fixtures - ============== - - A Fixture represents some state. Each fixture has attributes on it that are - specific to the fixture. For instance, a fixture representing a directory that - can be used for temporary files might have a attribute 'path'. - - Most fixtures have complete ``pydoc`` documentation, so be sure to check - ``pydoc fixtures`` for usage information. - - Creating Fixtures - ================= - - Minimally, subclass Fixture, define _setUp to initialize your state and schedule - a cleanup for when cleanUp is called and you're done:: - - >>> import unittest - >>> import fixtures - >>> class NoddyFixture(fixtures.Fixture): - ... def _setUp(self): - ... self.frobnozzle = 42 - ... self.addCleanup(delattr, self, 'frobnozzle') - - This will initialize frobnozzle when ``setUp`` is called, and when ``cleanUp`` - is called get rid of the frobnozzle attribute. Prior to version 1.3.0 fixtures - recommended overriding ``setUp``. This is still supported, but since it is - harder to write leak-free fixtures in this fashion, it is not recommended. - - If your fixture has diagnostic data - for instance the log file of an - application server, or log messages, it can expose that by creating a content - object (``testtools.content.Content``) and calling ``addDetail``. - - >>> from testtools.content import text_content - >>> class WithLog(fixtures.Fixture): - ... def _setUp(self): - ... self.addDetail('message', text_content('foo bar baz')) - - The method ``useFixture`` will use another fixture, call ``setUp`` on it, call - ``self.addCleanup(thefixture.cleanUp)``, attach any details from it and return - the fixture. This allows simple composition of different fixtures. - - >>> class ReusingFixture(fixtures.Fixture): - ... def _setUp(self): - ... self.noddy = self.useFixture(NoddyFixture()) - - There is a helper for adapting a function or function pair into Fixtures. it - puts the result of the function in fn_result:: - - >>> import os.path - >>> import shutil - >>> import tempfile - >>> def setup_function(): - ... return tempfile.mkdtemp() - >>> def teardown_function(fixture): - ... shutil.rmtree(fixture) - >>> fixture = fixtures.FunctionFixture(setup_function, teardown_function) - >>> fixture.setUp() - >>> print (os.path.isdir(fixture.fn_result)) - True - >>> fixture.cleanUp() - - This can be expressed even more pithily: - - >>> fixture = fixtures.FunctionFixture(tempfile.mkdtemp, shutil.rmtree) - >>> fixture.setUp() - >>> print (os.path.isdir(fixture.fn_result)) - True - >>> fixture.cleanUp() - - Another variation is MethodFixture which is useful for adapting alternate - fixture implementations to Fixture:: - - >>> class MyServer: - ... def start(self): - ... pass - ... def stop(self): - ... pass - >>> server = MyServer() - >>> fixture = fixtures.MethodFixture(server, server.start, server.stop) - - You can also combine existing fixtures using ``CompoundFixture``:: - - >>> noddy_with_log = fixtures.CompoundFixture(NoddyFixture(), - ... WithLog()) - >>> with noddy_with_log as x: - ... print (x.fixtures0.frobnozzle) - 42 - - The Fixture API - =============== - - The example above introduces some of the Fixture API. In order to be able to - clean up after a fixture has been used, all fixtures define a ``cleanUp`` - method which should be called when a fixture is finished with. - - Because it's nice to be able to build a particular set of related fixtures in - advance of using them, fixtures also have a ``setUp`` method which should be - called before trying to use them. - - One common desire with fixtures that are expensive to create is to reuse them - in many test cases; to support this the base Fixture also defines a ``reset`` - which calls ``self.cleanUp(); self.setUp()``. Fixtures that can more - efficiently make themselves reusable should override this method. This can then - be used with multiple test state via things like ``testresources``, - ``setUpClass``, or ``setUpModule``. - - When using a fixture with a test you can manually call the setUp and cleanUp - methods. More convenient though is to use the included glue from - ``fixtures.TestWithFixtures`` which provides a mixin defining - ``useFixture`` (camel case because unittest is camel case throughout) method. - It will call setUp on the fixture, call self.addCleanup(fixture) to schedule a - cleanup, and return the fixture. This lets one write:: - - >>> import testtools - >>> import unittest - - Note that we use testtools TestCase here as we need to guarantee a - TestCase.addCleanup method in this doctest. Unittest2 - Python2.7 and above - - also have ``addCleanup``. testtools has it's own implementation of - ``useFixture`` so there is no need to use ``fixtures.TestWithFixtures`` with - ``testtools.TestCase``. - - >>> class NoddyTest(testtools.TestCase, fixtures.TestWithFixtures):
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/README
Deleted
@@ -1,505 +0,0 @@ -************************************************************* -fixtures: Fixtures with cleanups for testing and convenience. -************************************************************* - - Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> - - Licensed under either the Apache License, Version 2.0 or the BSD 3-clause - license at the users choice. A copy of both licenses are available in the - project source as Apache-2.0 and BSD. You may not use this file except in - compliance with one of these two licences. - - Unless required by applicable law or agreed to in writing, software - distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - license you chose for the specific language governing permissions and - limitations under that license. - - -Fixtures defines a Python contract for reusable state / support logic, -primarily for unit testing. Helper and adaption logic is included to make it -easy to write your own fixtures using the fixtures contract. Glue code is -provided that makes using fixtures that meet the Fixtures contract in unittest -compatible test cases easy and straight forward. - -Dependencies -============ - -* Python 2.6+, or 3.3+ - This is the base language fixtures is written in and for. - -* pbr - Used for version and release management of fixtures. - -* testtools <https://launchpad.net/testtools> 0.9.22 or newer. - testtools provides helpful glue functions for the details API used to report - information about a fixture (whether its used in a testing or production - environment). - -For use in a unit test suite using the included glue, one of: - -* Python 2.7+ - -* unittest2 - -* bzrlib.tests - -* Or any other test environment that supports TestCase.addCleanup. - -Writing your own glue code is easy, or you can simply use Fixtures directly -without any support code. - -To run the test suite for fixtures, testtools is needed. - -Why Fixtures -============ - -Standard Python unittest.py provides no obvious method for making and reusing -state needed in a test case other than by adding a method on the test class. -This scales poorly - complex helper functions propagating up a test class -hierarchy is a regular pattern when this is done. Mocking while a great tool -doesn't itself prevent this (and helpers to mock complex things can accumulate -in the same way if placed on the test class). - -By defining a uniform contract where helpers have no dependency on the test -class we permit all the regular code hygiene activities to take place without -the distorting influence of being in a class hierarchy that is modelling an -entirely different thing - which is what helpers on a TestCase suffer from. - -About Fixtures -============== - -A Fixture represents some state. Each fixture has attributes on it that are -specific to the fixture. For instance, a fixture representing a directory that -can be used for temporary files might have a attribute 'path'. - -Most fixtures have complete ``pydoc`` documentation, so be sure to check -``pydoc fixtures`` for usage information. - -Creating Fixtures -================= - -Minimally, subclass Fixture, define _setUp to initialize your state and schedule -a cleanup for when cleanUp is called and you're done:: - - >>> import unittest - >>> import fixtures - >>> class NoddyFixture(fixtures.Fixture): - ... def _setUp(self): - ... self.frobnozzle = 42 - ... self.addCleanup(delattr, self, 'frobnozzle') - -This will initialize frobnozzle when ``setUp`` is called, and when ``cleanUp`` -is called get rid of the frobnozzle attribute. Prior to version 1.3.0 fixtures -recommended overriding ``setUp``. This is still supported, but since it is -harder to write leak-free fixtures in this fashion, it is not recommended. - -If your fixture has diagnostic data - for instance the log file of an -application server, or log messages, it can expose that by creating a content -object (``testtools.content.Content``) and calling ``addDetail``. - - >>> from testtools.content import text_content - >>> class WithLog(fixtures.Fixture): - ... def _setUp(self): - ... self.addDetail('message', text_content('foo bar baz')) - -The method ``useFixture`` will use another fixture, call ``setUp`` on it, call -``self.addCleanup(thefixture.cleanUp)``, attach any details from it and return -the fixture. This allows simple composition of different fixtures. - - >>> class ReusingFixture(fixtures.Fixture): - ... def _setUp(self): - ... self.noddy = self.useFixture(NoddyFixture()) - -There is a helper for adapting a function or function pair into Fixtures. it -puts the result of the function in fn_result:: - - >>> import os.path - >>> import shutil - >>> import tempfile - >>> def setup_function(): - ... return tempfile.mkdtemp() - >>> def teardown_function(fixture): - ... shutil.rmtree(fixture) - >>> fixture = fixtures.FunctionFixture(setup_function, teardown_function) - >>> fixture.setUp() - >>> print (os.path.isdir(fixture.fn_result)) - True - >>> fixture.cleanUp() - -This can be expressed even more pithily: - - >>> fixture = fixtures.FunctionFixture(tempfile.mkdtemp, shutil.rmtree) - >>> fixture.setUp() - >>> print (os.path.isdir(fixture.fn_result)) - True - >>> fixture.cleanUp() - -Another variation is MethodFixture which is useful for adapting alternate -fixture implementations to Fixture:: - - >>> class MyServer: - ... def start(self): - ... pass - ... def stop(self): - ... pass - >>> server = MyServer() - >>> fixture = fixtures.MethodFixture(server, server.start, server.stop) - -You can also combine existing fixtures using ``CompoundFixture``:: - - >>> noddy_with_log = fixtures.CompoundFixture(NoddyFixture(), - ... WithLog()) - >>> with noddy_with_log as x: - ... print (x.fixtures0.frobnozzle) - 42 - -The Fixture API -=============== - -The example above introduces some of the Fixture API. In order to be able to -clean up after a fixture has been used, all fixtures define a ``cleanUp`` -method which should be called when a fixture is finished with. - -Because it's nice to be able to build a particular set of related fixtures in -advance of using them, fixtures also have a ``setUp`` method which should be -called before trying to use them. - -One common desire with fixtures that are expensive to create is to reuse them -in many test cases; to support this the base Fixture also defines a ``reset`` -which calls ``self.cleanUp(); self.setUp()``. Fixtures that can more -efficiently make themselves reusable should override this method. This can then -be used with multiple test state via things like ``testresources``, -``setUpClass``, or ``setUpModule``. - -When using a fixture with a test you can manually call the setUp and cleanUp -methods. More convenient though is to use the included glue from -``fixtures.TestWithFixtures`` which provides a mixin defining -``useFixture`` (camel case because unittest is camel case throughout) method. -It will call setUp on the fixture, call self.addCleanup(fixture) to schedule a -cleanup, and return the fixture. This lets one write:: - - >>> import testtools - >>> import unittest - -Note that we use testtools TestCase here as we need to guarantee a -TestCase.addCleanup method in this doctest. Unittest2 - Python2.7 and above - -also have ``addCleanup``. testtools has it's own implementation of -``useFixture`` so there is no need to use ``fixtures.TestWithFixtures`` with -``testtools.TestCase``. - - >>> class NoddyTest(testtools.TestCase, fixtures.TestWithFixtures): - ... def test_example(self): - ... fixture = self.useFixture(NoddyFixture()) - ... self.assertEqual(42, fixture.frobnozzle) - >>> result = unittest.TestResult() - >>> _ = NoddyTest('test_example').run(result) - >>> print (result.wasSuccessful()) - True -
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info
Deleted
-(directory)
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/PKG-INFO
Deleted
@@ -1,525 +0,0 @@ -Metadata-Version: 1.1 -Name: fixtures -Version: 3.0.0 -Summary: Fixtures, reusable state for writing clean tests and more. -Home-page: https://launchpad.net/python-fixtures -Author: Robert Collins -Author-email: robertc@robertcollins.net -License: UNKNOWN -Description: ************************************************************* - fixtures: Fixtures with cleanups for testing and convenience. - ************************************************************* - - Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> - - Licensed under either the Apache License, Version 2.0 or the BSD 3-clause - license at the users choice. A copy of both licenses are available in the - project source as Apache-2.0 and BSD. You may not use this file except in - compliance with one of these two licences. - - Unless required by applicable law or agreed to in writing, software - distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - license you chose for the specific language governing permissions and - limitations under that license. - - - Fixtures defines a Python contract for reusable state / support logic, - primarily for unit testing. Helper and adaption logic is included to make it - easy to write your own fixtures using the fixtures contract. Glue code is - provided that makes using fixtures that meet the Fixtures contract in unittest - compatible test cases easy and straight forward. - - Dependencies - ============ - - * Python 2.6+, or 3.3+ - This is the base language fixtures is written in and for. - - * pbr - Used for version and release management of fixtures. - - * testtools <https://launchpad.net/testtools> 0.9.22 or newer. - testtools provides helpful glue functions for the details API used to report - information about a fixture (whether its used in a testing or production - environment). - - For use in a unit test suite using the included glue, one of: - - * Python 2.7+ - - * unittest2 - - * bzrlib.tests - - * Or any other test environment that supports TestCase.addCleanup. - - Writing your own glue code is easy, or you can simply use Fixtures directly - without any support code. - - To run the test suite for fixtures, testtools is needed. - - Why Fixtures - ============ - - Standard Python unittest.py provides no obvious method for making and reusing - state needed in a test case other than by adding a method on the test class. - This scales poorly - complex helper functions propagating up a test class - hierarchy is a regular pattern when this is done. Mocking while a great tool - doesn't itself prevent this (and helpers to mock complex things can accumulate - in the same way if placed on the test class). - - By defining a uniform contract where helpers have no dependency on the test - class we permit all the regular code hygiene activities to take place without - the distorting influence of being in a class hierarchy that is modelling an - entirely different thing - which is what helpers on a TestCase suffer from. - - About Fixtures - ============== - - A Fixture represents some state. Each fixture has attributes on it that are - specific to the fixture. For instance, a fixture representing a directory that - can be used for temporary files might have a attribute 'path'. - - Most fixtures have complete ``pydoc`` documentation, so be sure to check - ``pydoc fixtures`` for usage information. - - Creating Fixtures - ================= - - Minimally, subclass Fixture, define _setUp to initialize your state and schedule - a cleanup for when cleanUp is called and you're done:: - - >>> import unittest - >>> import fixtures - >>> class NoddyFixture(fixtures.Fixture): - ... def _setUp(self): - ... self.frobnozzle = 42 - ... self.addCleanup(delattr, self, 'frobnozzle') - - This will initialize frobnozzle when ``setUp`` is called, and when ``cleanUp`` - is called get rid of the frobnozzle attribute. Prior to version 1.3.0 fixtures - recommended overriding ``setUp``. This is still supported, but since it is - harder to write leak-free fixtures in this fashion, it is not recommended. - - If your fixture has diagnostic data - for instance the log file of an - application server, or log messages, it can expose that by creating a content - object (``testtools.content.Content``) and calling ``addDetail``. - - >>> from testtools.content import text_content - >>> class WithLog(fixtures.Fixture): - ... def _setUp(self): - ... self.addDetail('message', text_content('foo bar baz')) - - The method ``useFixture`` will use another fixture, call ``setUp`` on it, call - ``self.addCleanup(thefixture.cleanUp)``, attach any details from it and return - the fixture. This allows simple composition of different fixtures. - - >>> class ReusingFixture(fixtures.Fixture): - ... def _setUp(self): - ... self.noddy = self.useFixture(NoddyFixture()) - - There is a helper for adapting a function or function pair into Fixtures. it - puts the result of the function in fn_result:: - - >>> import os.path - >>> import shutil - >>> import tempfile - >>> def setup_function(): - ... return tempfile.mkdtemp() - >>> def teardown_function(fixture): - ... shutil.rmtree(fixture) - >>> fixture = fixtures.FunctionFixture(setup_function, teardown_function) - >>> fixture.setUp() - >>> print (os.path.isdir(fixture.fn_result)) - True - >>> fixture.cleanUp() - - This can be expressed even more pithily: - - >>> fixture = fixtures.FunctionFixture(tempfile.mkdtemp, shutil.rmtree) - >>> fixture.setUp() - >>> print (os.path.isdir(fixture.fn_result)) - True - >>> fixture.cleanUp() - - Another variation is MethodFixture which is useful for adapting alternate - fixture implementations to Fixture:: - - >>> class MyServer: - ... def start(self): - ... pass - ... def stop(self): - ... pass - >>> server = MyServer() - >>> fixture = fixtures.MethodFixture(server, server.start, server.stop) - - You can also combine existing fixtures using ``CompoundFixture``:: - - >>> noddy_with_log = fixtures.CompoundFixture(NoddyFixture(), - ... WithLog()) - >>> with noddy_with_log as x: - ... print (x.fixtures0.frobnozzle) - 42 - - The Fixture API - =============== - - The example above introduces some of the Fixture API. In order to be able to - clean up after a fixture has been used, all fixtures define a ``cleanUp`` - method which should be called when a fixture is finished with. - - Because it's nice to be able to build a particular set of related fixtures in - advance of using them, fixtures also have a ``setUp`` method which should be - called before trying to use them. - - One common desire with fixtures that are expensive to create is to reuse them - in many test cases; to support this the base Fixture also defines a ``reset`` - which calls ``self.cleanUp(); self.setUp()``. Fixtures that can more - efficiently make themselves reusable should override this method. This can then - be used with multiple test state via things like ``testresources``, - ``setUpClass``, or ``setUpModule``. - - When using a fixture with a test you can manually call the setUp and cleanUp - methods. More convenient though is to use the included glue from - ``fixtures.TestWithFixtures`` which provides a mixin defining - ``useFixture`` (camel case because unittest is camel case throughout) method. - It will call setUp on the fixture, call self.addCleanup(fixture) to schedule a - cleanup, and return the fixture. This lets one write:: - - >>> import testtools - >>> import unittest - - Note that we use testtools TestCase here as we need to guarantee a - TestCase.addCleanup method in this doctest. Unittest2 - Python2.7 and above - - also have ``addCleanup``. testtools has it's own implementation of - ``useFixture`` so there is no need to use ``fixtures.TestWithFixtures`` with - ``testtools.TestCase``. - - >>> class NoddyTest(testtools.TestCase, fixtures.TestWithFixtures):
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/SOURCES.txt
Deleted
@@ -1,61 +0,0 @@ -.testr.conf -.travis.yml -AUTHORS -Apache-2.0 -BSD -COPYING -ChangeLog -GOALS -HACKING -MANIFEST.in -Makefile -NEWS -README -requirements.txt -setup.cfg -setup.py -tox.ini -fixtures/__init__.py -fixtures/callmany.py -fixtures/fixture.py -fixtures/testcase.py -fixtures.egg-info/PKG-INFO -fixtures.egg-info/SOURCES.txt -fixtures.egg-info/dependency_links.txt -fixtures.egg-info/not-zip-safe -fixtures.egg-info/pbr.json -fixtures.egg-info/requires.txt -fixtures.egg-info/top_level.txt -fixtures/_fixtures/__init__.py -fixtures/_fixtures/environ.py -fixtures/_fixtures/logger.py -fixtures/_fixtures/mockpatch.py -fixtures/_fixtures/monkeypatch.py -fixtures/_fixtures/packagepath.py -fixtures/_fixtures/popen.py -fixtures/_fixtures/pythonpackage.py -fixtures/_fixtures/pythonpath.py -fixtures/_fixtures/streams.py -fixtures/_fixtures/tempdir.py -fixtures/_fixtures/temphomedir.py -fixtures/_fixtures/timeout.py -fixtures/_fixtures/warnings.py -fixtures/tests/__init__.py -fixtures/tests/helpers.py -fixtures/tests/test_callmany.py -fixtures/tests/test_fixture.py -fixtures/tests/test_testcase.py -fixtures/tests/_fixtures/__init__.py -fixtures/tests/_fixtures/test_environ.py -fixtures/tests/_fixtures/test_logger.py -fixtures/tests/_fixtures/test_mockpatch.py -fixtures/tests/_fixtures/test_monkeypatch.py -fixtures/tests/_fixtures/test_packagepath.py -fixtures/tests/_fixtures/test_popen.py -fixtures/tests/_fixtures/test_pythonpackage.py -fixtures/tests/_fixtures/test_pythonpath.py -fixtures/tests/_fixtures/test_streams.py -fixtures/tests/_fixtures/test_tempdir.py -fixtures/tests/_fixtures/test_temphomedir.py -fixtures/tests/_fixtures/test_timeout.py -fixtures/tests/_fixtures/test_warnings.py \ No newline at end of file
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/dependency_links.txt
Deleted
@@ -1,1 +0,0 @@ -
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/not-zip-safe
Deleted
@@ -1,1 +0,0 @@ -
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/pbr.json
Deleted
@@ -1,1 +0,0 @@ -{"is_release": true, "git_version": "c2c28a1"} \ No newline at end of file
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/requires.txt
Deleted
@@ -1,9 +0,0 @@ -pbr>=0.11 -six -testtools>=0.9.22 - -docs -docutils - -test -mock
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures.egg-info/top_level.txt
Deleted
@@ -1,1 +0,0 @@ -fixtures
View file
_service:tar_scm:fixtures-4.0.1.tar.gz/.github
Added
+(directory)
View file
_service:tar_scm:fixtures-4.0.1.tar.gz/.github/workflows
Added
+(directory)
View file
_service:tar_scm:fixtures-4.0.1.tar.gz/.github/workflows/ci.yaml
Added
@@ -0,0 +1,71 @@ +--- +name: CI +on: + - push + - pull_request +jobs: + test: + name: Run unit tests + runs-on: ubuntu-latest + strategy: + matrix: + python: "3.6", "3.7", "3.8", "3.9", "3.10", "3.11.0-beta - 3.11", "pypy-3.7", "pypy-3.8", "pypy-3.9" + steps: + - name: Checkout source code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install dependencies + run: python -m pip install tox + - name: Run unit tests (via tox) + # Run tox using the version of Python in `PATH` + run: tox -e py + docs: + name: Build docs + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install dependencies + run: python -m pip install docutils + - name: Build docs + run: rst2html.py README.rst README.html + - name: Archive build results + uses: actions/upload-artifact@v2 + with: + name: html-docs-build + path: README.html + retention-days: 7 + release: + name: Upload release artifacts + runs-on: ubuntu-latest + needs: test + if: github.event_name == 'push' + steps: + - name: Checkout source code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install dependencies + run: python -m pip install build + - name: Build a binary wheel and a source tarball + run: python -m build --sdist --wheel --outdir dist/ . + - name: Publish distribution to PyPI + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.PYPI_API_TOKEN }}
View file
_service:tar_scm:fixtures-4.0.1.tar.gz/.gitignore
Added
@@ -0,0 +1,16 @@ +TAGS +tags +lib/testtools +MANIFEST +dist +.testrepository +__pycache__ +fixtures.egg-info +*.pyc +.*.swp +*~ +AUTHORS +ChangeLog +.eggs +build +.tox
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/HACKING -> _service:tar_scm:fixtures-4.0.1.tar.gz/HACKING
Changed
@@ -9,7 +9,7 @@ git clone https://github.com/testing-cabal/fixtures path-to-new-local-repo -Publish your branches whereever you like and submit PR's on github. +Publish your branches wherever you like and submit PR's on github. Copyright +++++++++
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/NEWS -> _service:tar_scm:fixtures-4.0.1.tar.gz/NEWS
Changed
@@ -2,10 +2,38 @@ fixtures release notes ---------------------- - NEXT ~~~~ +4.0.1 +~~~~~ + +* Remove ``testtools`` from ``requirements.txt`` as well. + (Colin Watson) + +4.0.0 +~~~~~ + +* Add missing APIs to ``FakeProcess``, making it match ``Popen``. + (Free Ekanayaka, #1373224) + +* Dropped support for Python 2.7, Python 3.4 and Python 3.5 (EOL). + (Hugo van Kemenade) + +* Added support for Python 3.6-3.10. + (Free Ekanayaka, Stephen Finucane, Colin Watson) + +* Add possibility to reset the ``FakeLogger``. (Balazs Gibizer) + +* Access ``mock.DEFAULT`` lazily rather than at import time so ``mock`` can + be overridden with something else. (Jelmer Vernooij) + +* Support all ``subprocess.Popen`` arguments up to Python 3.10. + (Jürgen Gmach, Colin Watson) + +* Move ``testtools`` requirement to a new ``fixturesstreams`` extra. + (Colin Watson) + 3.0.0 ~~~~~ @@ -349,7 +377,7 @@ 0.3 ~~~ -This release slightly breaks compatability in order to get the cleanUp API +This release slightly breaks compatibility in order to get the cleanUp API really solid : it now will report correctly with testtools 0.9.7, and generally does the right thing by default. Apologies to anyone affected by this churn, but I felt the cleanness of the API was worth it.
View file
_service:tar_scm:fixtures-4.0.1.tar.gz/README.rst
Added
@@ -0,0 +1,504 @@ +************************************************************* +fixtures: Fixtures with cleanups for testing and convenience. +************************************************************* + + Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> + + Licensed under either the Apache License, Version 2.0 or the BSD 3-clause + license at the users choice. A copy of both licenses are available in the + project source as Apache-2.0 and BSD. You may not use this file except in + compliance with one of these two licences. + + Unless required by applicable law or agreed to in writing, software + distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + license you chose for the specific language governing permissions and + limitations under that license. + + +Fixtures defines a Python contract for reusable state / support logic, +primarily for unit testing. Helper and adaption logic is included to make it +easy to write your own fixtures using the fixtures contract. Glue code is +provided that makes using fixtures that meet the Fixtures contract in unittest +compatible test cases easy and straight forward. + +Dependencies +============ + +* Python 3.6+ + This is the base language fixtures is written in and for. + +* pbr + Used for version and release management of fixtures. + +The ``fixturesstreams`` extra adds: + +* testtools <https://launchpad.net/testtools> 0.9.22 or newer. + testtools provides helpful glue functions for the details API used to report + information about a fixture (whether its used in a testing or production + environment). + +For use in a unit test suite using the included glue, one of: + +* bzrlib.tests + +* Or any other test environment that supports TestCase.addCleanup. + +Writing your own glue code is easy, or you can simply use Fixtures directly +without any support code. + +To run the test suite for fixtures, testtools is needed. + +Why Fixtures +============ + +Standard Python unittest.py provides no obvious method for making and reusing +state needed in a test case other than by adding a method on the test class. +This scales poorly - complex helper functions propagating up a test class +hierarchy is a regular pattern when this is done. Mocking while a great tool +doesn't itself prevent this (and helpers to mock complex things can accumulate +in the same way if placed on the test class). + +By defining a uniform contract where helpers have no dependency on the test +class we permit all the regular code hygiene activities to take place without +the distorting influence of being in a class hierarchy that is modelling an +entirely different thing - which is what helpers on a TestCase suffer from. + +About Fixtures +============== + +A Fixture represents some state. Each fixture has attributes on it that are +specific to the fixture. For instance, a fixture representing a directory that +can be used for temporary files might have a attribute 'path'. + +Most fixtures have complete ``pydoc`` documentation, so be sure to check +``pydoc fixtures`` for usage information. + +Creating Fixtures +================= + +Minimally, subclass Fixture, define _setUp to initialize your state and schedule +a cleanup for when cleanUp is called and you're done:: + + >>> import unittest + >>> import fixtures + >>> class NoddyFixture(fixtures.Fixture): + ... def _setUp(self): + ... self.frobnozzle = 42 + ... self.addCleanup(delattr, self, 'frobnozzle') + +This will initialize frobnozzle when ``setUp`` is called, and when ``cleanUp`` +is called get rid of the frobnozzle attribute. Prior to version 1.3.0 fixtures +recommended overriding ``setUp``. This is still supported, but since it is +harder to write leak-free fixtures in this fashion, it is not recommended. + +If your fixture has diagnostic data - for instance the log file of an +application server, or log messages, it can expose that by creating a content +object (``testtools.content.Content``) and calling ``addDetail``. + + >>> from testtools.content import text_content + >>> class WithLog(fixtures.Fixture): + ... def _setUp(self): + ... self.addDetail('message', text_content('foo bar baz')) + +The method ``useFixture`` will use another fixture, call ``setUp`` on it, call +``self.addCleanup(thefixture.cleanUp)``, attach any details from it and return +the fixture. This allows simple composition of different fixtures. + + >>> class ReusingFixture(fixtures.Fixture): + ... def _setUp(self): + ... self.noddy = self.useFixture(NoddyFixture()) + +There is a helper for adapting a function or function pair into Fixtures. it +puts the result of the function in fn_result:: + + >>> import os.path + >>> import shutil + >>> import tempfile + >>> def setup_function(): + ... return tempfile.mkdtemp() + >>> def teardown_function(fixture): + ... shutil.rmtree(fixture) + >>> fixture = fixtures.FunctionFixture(setup_function, teardown_function) + >>> fixture.setUp() + >>> print (os.path.isdir(fixture.fn_result)) + True + >>> fixture.cleanUp() + +This can be expressed even more pithily: + + >>> fixture = fixtures.FunctionFixture(tempfile.mkdtemp, shutil.rmtree) + >>> fixture.setUp() + >>> print (os.path.isdir(fixture.fn_result)) + True + >>> fixture.cleanUp() + +Another variation is MethodFixture which is useful for adapting alternate +fixture implementations to Fixture:: + + >>> class MyServer: + ... def start(self): + ... pass + ... def stop(self): + ... pass + >>> server = MyServer() + >>> fixture = fixtures.MethodFixture(server, server.start, server.stop) + +You can also combine existing fixtures using ``CompoundFixture``:: + + >>> noddy_with_log = fixtures.CompoundFixture(NoddyFixture(), + ... WithLog()) + >>> with noddy_with_log as x: + ... print (x.fixtures0.frobnozzle) + 42 + +The Fixture API +=============== + +The example above introduces some of the Fixture API. In order to be able to +clean up after a fixture has been used, all fixtures define a ``cleanUp`` +method which should be called when a fixture is finished with. + +Because it's nice to be able to build a particular set of related fixtures in +advance of using them, fixtures also have a ``setUp`` method which should be +called before trying to use them. + +One common desire with fixtures that are expensive to create is to reuse them +in many test cases; to support this the base Fixture also defines a ``reset`` +which calls ``self.cleanUp(); self.setUp()``. Fixtures that can more +efficiently make themselves reusable should override this method. This can then +be used with multiple test state via things like ``testresources``, +``setUpClass``, or ``setUpModule``. + +When using a fixture with a test you can manually call the setUp and cleanUp +methods. More convenient though is to use the included glue from +``fixtures.TestWithFixtures`` which provides a mixin defining +``useFixture`` (camel case because unittest is camel case throughout) method. +It will call setUp on the fixture, call self.addCleanup(fixture) to schedule a +cleanup, and return the fixture. This lets one write:: + + >>> import testtools + >>> import unittest + +Note that we use ``testtools.TestCase``. testtools has it's own implementation +of ``useFixture`` so there is no need to use ``fixtures.TestWithFixtures`` with +``testtools.TestCase``. + + >>> class NoddyTest(testtools.TestCase, fixtures.TestWithFixtures): + ... def test_example(self): + ... fixture = self.useFixture(NoddyFixture()) + ... self.assertEqual(42, fixture.frobnozzle) + >>> result = unittest.TestResult() + >>> _ = NoddyTest('test_example').run(result) + >>> print (result.wasSuccessful()) + True + +Fixtures implement the context protocol, so you can also use a fixture as a +context manager:: + + >>> with fixtures.FunctionFixture(setup_function, teardown_function) as fixture:
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/__init__.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/__init__.py
Changed
@@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -29,7 +29,7 @@ # the version number: major, minor, micro, releaselevel, and serial. All # values except releaselevel are integers; the release level is 'alpha', # 'beta', 'candidate', or 'final'. The version_info value corresponding to the -# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a +# Python version 3.9 is (3, 9, 0, 'final', 0)." Additionally we use a # releaselevel of 'dev' for unreleased under-development code. # # If the releaselevel is 'alpha' then the major/minor/micro components are not
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/_fixtures/logger.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/_fixtures/logger.py
Changed
@@ -16,9 +16,6 @@ from logging import StreamHandler, getLogger, INFO, Formatter import sys -import six -from testtools.compat import _u - from fixtures import Fixture from fixtures._fixtures.streams import StringStream @@ -66,7 +63,8 @@ class StreamHandlerRaiseException(StreamHandler): """Handler class that will raise an exception on formatting errors.""" def handleError(self, record): - six.reraise(*sys.exc_info()) + _, value, tb = sys.exc_info() + raise value.with_traceback(tb) class FakeLogger(Fixture): @@ -103,7 +101,7 @@ self._formatter = formatter def _setUp(self): - name = _u("pythonlogging:'%s'") % self._name + name = "pythonlogging:'%s'" % self._name output = self.useFixture(StringStream(name)).stream self._output = output handler = StreamHandlerRaiseException(output) @@ -119,5 +117,8 @@ self._output.seek(0) return self._output.read() + def reset_output(self): + self._output.truncate(0) + LoggerFixture = FakeLogger
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/_fixtures/mockpatch.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/_fixtures/mockpatch.py
Changed
@@ -15,13 +15,13 @@ # License for the specific language governing permissions and limitations # under the License. -import extras - import fixtures -mock = extras.try_imports('mock', 'unittest.mock', None) -mock_default = extras.try_imports( - 'mock.DEFAULT', 'unittest.mock.DEFAULT', None) +# TODO(stephenfin): Make this configurable +try: + import mock +except ImportError: + import unittest.mock as mock class _Base(fixtures.Fixture): @@ -34,25 +34,41 @@ class MockPatchObject(_Base): """Deal with code around mock.""" - def __init__(self, obj, attr, new=mock_default, **kwargs): + def __init__(self, obj, attr, new=None, **kwargs): super(MockPatchObject, self).__init__() + if new is None: + new = mock.DEFAULT self._get_p = lambda: mock.patch.object(obj, attr, new, **kwargs) class MockPatch(_Base): """Deal with code around mock.patch.""" - def __init__(self, obj, new=mock_default, **kwargs): + def __init__(self, obj, new=None, **kwargs): super(MockPatch, self).__init__() + if new is None: + new = mock.DEFAULT self._get_p = lambda: mock.patch(obj, new, **kwargs) -class MockPatchMultiple(_Base): - """Deal with code around mock.patch.multiple.""" +class _MockPatchMultipleMeta(type): + """Arrange for lazy loading of MockPatchMultiple.DEFAULT.""" + + # For strict backward compatibility, ensure that DEFAULT also works as + # an instance property. + def __new__(cls, name, bases, namespace, **kwargs): + namespace'DEFAULT' = cls.DEFAULT + return super().__new__(cls, name, bases, namespace, **kwargs) # Default value to trigger a MagicMock to be created for a named # attribute. - DEFAULT = mock_default + @property + def DEFAULT(self): + return mock.DEFAULT + + +class MockPatchMultiple(_Base, metaclass=_MockPatchMultipleMeta): + """Deal with code around mock.patch.multiple.""" def __init__(self, obj, **kwargs): """Initialize the mocks
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/_fixtures/monkeypatch.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/_fixtures/monkeypatch.py
Changed
@@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -15,29 +15,25 @@ __all__ = 'MonkeyPatch' - + import functools -import sys import types from fixtures import Fixture _class_types = (type, ) -if getattr(types, 'ClassType', None): - # Python 2 has multiple types of classes. - _class_types = _class_types + (types.ClassType,) def _coerce_values(obj, name, new_value, sentinel): """Return an adapted (new_value, old_value) for patching obj.name. - + setattr transforms a function into an instancemethod when set on a class. This checks if the attribute to be replaced is a callable descriptor - staticmethod, classmethod, or types.FunctionType - and wraps new_value if necessary. - + This also checks getattr(obj, name) and wraps it if necessary since the staticmethod wrapper isn't preserved. @@ -84,9 +80,11 @@ # bound state rather than having it bound to the new object # it has been patched onto. captured_method = new_value + @functools.wraps(old_value) def avoid_get(*args, **kwargs): return captured_method(*args, **kwargs) + new_value = avoid_get return (new_value, old_value) @@ -130,7 +128,7 @@ Fixture.__init__(self) self.name = name self.new_value = new_value - + def _setUp(self): location, attribute = self.name.rsplit('.', 1) # Import, swallowing all errors as any element of location may be @@ -139,18 +137,21 @@ __import__(location, {}, {}) except ImportError: pass + components = location.split('.') current = __import__(components0, {}, {}) for component in components1:: current = getattr(current, component) sentinel = object() - new_value, old_value = _coerce_values(current, attribute, - self.new_value, sentinel) + new_value, old_value = _coerce_values( + current, attribute, self.new_value, sentinel) + if self.new_value is self.delete: if old_value is not sentinel: delattr(current, attribute) else: setattr(current, attribute, new_value) + if old_value is sentinel: self.addCleanup(self._safe_delete, current, attribute) else:
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/_fixtures/popen.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/_fixtures/popen.py
Changed
@@ -20,6 +20,7 @@ import random import subprocess +import sys from fixtures import Fixture @@ -36,8 +37,23 @@ self._returncode = info.get('returncode', 0) self.returncode = None - def communicate(self): + @property + def args(self): + return self._args"args" + + def poll(self): + """Get the current value of FakeProcess.returncode. + + The returncode is None before communicate() and/or wait() are called, + and it's set to the value provided by the 'info' dictionary otherwise + (or 0 in case 'info' doesn't specify a value). + """ + return self.returncode + + def communicate(self, input=None, timeout=None): self.returncode = self._returncode + if self.stdin and input: + self.stdin.write(input) if self.stdout: out = self.stdout.getvalue() else: @@ -91,6 +107,11 @@ The default behaviour if no get_info is supplied is for the return process to have returncode of None, empty streams and a random pid. + + After communicate() or wait() are called on the process object, + the returncode is set to whatever get_info returns (or 0 if + get_info is not supplied or doesn't return a dict with an explicit + 'returncode' key). """ super(FakePopen, self).__init__() self.get_info = get_info @@ -106,13 +127,43 @@ stdin=_unpassed, stdout=_unpassed, stderr=_unpassed, preexec_fn=_unpassed, close_fds=_unpassed, shell=_unpassed, cwd=_unpassed, env=_unpassed, universal_newlines=_unpassed, - startupinfo=_unpassed, creationflags=_unpassed): + startupinfo=_unpassed, creationflags=_unpassed, + restore_signals=_unpassed, start_new_session=_unpassed, + pass_fds=_unpassed, *, group=_unpassed, extra_groups=_unpassed, + user=_unpassed, umask=_unpassed, encoding=_unpassed, + errors=_unpassed, text=_unpassed, pipesize=_unpassed, + process_group=_unpassed): + # Reject arguments introduced by newer versions of Python in older + # versions; this makes it harder to accidentally hide compatibility + # problems using test doubles. + if sys.version_info < (3, 7) and text is not FakePopen._unpassed: + raise TypeError( + "FakePopen.__call__() got an unexpected keyword argument " + "'text'") + if sys.version_info < (3, 9): + for arg_name in "group", "extra_groups", "user", "umask": + if locals()arg_name is not FakePopen._unpassed: + raise TypeError( + "FakePopen.__call__() got an unexpected keyword " + "argument '{}'".format(arg_name)) + if sys.version_info < (3, 10) and pipesize is not FakePopen._unpassed: + raise TypeError( + "FakePopen.__call__() got an unexpected keyword argument " + "'pipesize'") + if sys.version_info < (3, 11) and process_group is not FakePopen._unpassed: + raise TypeError( + "FakePopen.__call__() got an unexpected keyword argument " + "'process_group'") + proc_args = dict(args=args) local = locals() for param in "bufsize", "executable", "stdin", "stdout", "stderr", "preexec_fn", "close_fds", "shell", "cwd", "env", - "universal_newlines", "startupinfo", "creationflags": + "universal_newlines", "startupinfo", "creationflags", + "restore_signals", "start_new_session", "pass_fds", "group", + "extra_groups", "user", "umask", "encoding", "errors", "text", + "pipesize", "process_group": if localparam is not FakePopen._unpassed: proc_argsparam = localparam proc_info = self.get_info(proc_args)
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/_fixtures/streams.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/_fixtures/streams.py
Changed
@@ -20,10 +20,8 @@ import io -import sys from fixtures import Fixture -import testtools class Stream(Fixture): @@ -43,10 +41,14 @@ self._stream_factory = stream_factory def _setUp(self): + # Available with the fixturesstreams extra. + from testtools.content import content_from_stream + write_stream, read_stream = self._stream_factory() self.stream = write_stream - self.addDetail(self._detail_name, - testtools.content.content_from_stream(read_stream, seek_offset=0)) + self.addDetail( + self._detail_name, + content_from_stream(read_stream, seek_offset=0)) def _byte_stream_factory(): @@ -69,15 +71,6 @@ upper = io.TextIOWrapper(lower, encoding="utf8") # See http://bugs.python.org/issue7955 upper._CHUNK_SIZE = 1 - # In theory, this is sufficient and correct, but on Python2, - # upper.write(_b('foo")) will whinge louadly. - if sys.version_info0 < 3: - upper_write = upper.write - def safe_write(str_or_bytes): - if type(str_or_bytes) is str: - str_or_bytes = str_or_bytes.decode('utf8') - return upper_write(str_or_bytes) - upper.write = safe_write return upper, lower
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/callmany.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/callmany.py
Changed
@@ -19,17 +19,12 @@ import sys -from testtools.compat import ( - reraise, - ) -from testtools.helpers import try_import - -class MultipleExceptions(Exception): - """Report multiple exc_info tuples in self.args.""" - -MultipleExceptions = try_import( - "testtools.MultipleExceptions", MultipleExceptions) +try: + from testtools import MultipleExceptions +except ImportError: + class MultipleExceptions(Exception): + """Report multiple exc_info tuples in self.args.""" class CallMany(object): @@ -70,10 +65,10 @@ Thus, to catch a specific exception from a function run by __call__, you need to catch both the exception and MultipleExceptions, and - then check within a MultipleExceptions instance for an occurance of + then check within a MultipleExceptions instance for an occurrence of the type you wish to catch. :return: Either None or a list of the exc_info() for each exception - that occured if raise_errors was False. + that occurred if raise_errors was False. """ cleanups = reversed(self._cleanups) self._cleanups = @@ -86,7 +81,7 @@ if result and raise_errors: if 1 == len(result): error = result0 - reraise(error0, error1, error2) + raise error1.with_traceback(error2) else: raise MultipleExceptions(*result) if not raise_errors:
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/fixture.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/fixture.py
Changed
@@ -25,19 +25,18 @@ import itertools import sys -import six -from testtools.compat import ( - advance_iterator, - ) -from testtools.helpers import try_import - from fixtures.callmany import ( CallMany, # Deprecated, imported for compatibility. MultipleExceptions, ) -gather_details = try_import("testtools.testcase.gather_details") + +try: + from testtools.testcase import gather_details +except ImportError: + gather_details = None + # This would be better in testtools (or a common library) def combine_details(source_details, target_details): @@ -46,7 +45,7 @@ new_name = name disambiguator = itertools.count(1) while new_name in target_details: - new_name = '%s-%d' % (name, advance_iterator(disambiguator)) + new_name = '%s-%d' % (name, next(disambiguator)) name = new_name target_detailsname = content_object @@ -118,7 +117,7 @@ Thus, to catch a specific exception from cleanUp, you need to catch both the exception and MultipleExceptions, and then check within a MultipleExceptions instance for the type you're catching. - :return: A list of the exc_info() for each exception that occured if + :return: A list of the exc_info() for each exception that occurred if raise_first was False """ try: @@ -211,7 +210,7 @@ if issubclass(err0, Exception): raise MultipleExceptions(*errors) else: - six.reraise(*err) + raise err1.with_traceback(err2) def _setUp(self): """Template method for subclasses to override.
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/__init__.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/__init__.py
Changed
@@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -14,11 +14,8 @@ # limitations under that license. import doctest -import sys import unittest -import fixtures.tests._fixtures - def test_suite(): standard_tests = unittest.TestSuite() @@ -35,13 +32,8 @@ prefix = "fixtures.tests.test_" test_mod_names = prefix + test_module for test_module in test_modules standard_tests.addTests(loader.loadTestsFromNames(test_mod_names)) - if sys.version_info >= (2, 7): - # 2.7 calls load_tests for us - standard_tests.addTests(loader.loadTestsFromName('fixtures.tests._fixtures')) - else: - # We need to call it ourselves. - standard_tests.addTests(fixtures.tests._fixtures.load_tests( - loader, loader.loadTestsFromName('fixtures.tests._fixtures'), pattern)) + standard_tests.addTests( + loader.loadTestsFromName('fixtures.tests._fixtures')) doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE) - standard_tests.addTest(doctest.DocFileSuite("../../README")) + standard_tests.addTest(doctest.DocFileSuite("../../README.rst")) return standard_tests
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/_fixtures/test_logger.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/_fixtures/test_logger.py
Changed
@@ -13,13 +13,12 @@ # license you chose for the specific language governing permissions and # limitations under that license. +import io import logging -import sys import time import testtools from testtools import TestCase -from testtools.compat import StringIO from fixtures import ( FakeLogger, @@ -32,12 +31,8 @@ # testing formatter overrides. class FooFormatter(logging.Formatter): def format(self, record): - # custom formatters interface changes in python 3.2 - if sys.version_info < (3, 2): - self._fmt = "Foo " + self._fmt - else: - self._style = logging.PercentStyle("Foo " + self._style._fmt) - self._fmt = self._style._fmt + self._style = logging.PercentStyle("Foo " + self._style._fmt) + self._fmt = self._style._fmt return logging.Formatter.format(self, record) @@ -58,7 +53,7 @@ self.assertEqual("some message\n", fixture.output) def test_replace_and_restore_handlers(self): - stream = StringIO() + stream = io.StringIO() logger = logging.getLogger() logger.addHandler(logging.StreamHandler(stream)) logger.setLevel(logging.INFO) @@ -71,7 +66,7 @@ self.assertEqual("one\nthree\n", stream.getvalue()) def test_preserving_existing_handlers(self): - stream = StringIO() + stream = io.StringIO() self.logger.addHandler(logging.StreamHandler(stream)) self.logger.setLevel(logging.INFO) fixture = FakeLogger(nuke_handlers=False) @@ -146,6 +141,15 @@ with testtools.ExpectedException(TypeError): logging.info("Some message", "wrongarg") + def test_output_can_be_reset(self): + fixture = FakeLogger() + with fixture: + logging.info("message") + + fixture.reset_output() + + self.assertEqual("", fixture.output) + class LogHandlerTest(TestCase, TestWithFixtures): @@ -174,7 +178,7 @@ self.assertEqual("some message", fixture.handler.msgs) def test_replace_and_restore_handlers(self): - stream = StringIO() + stream = io.StringIO() logger = logging.getLogger() logger.addHandler(logging.StreamHandler(stream)) logger.setLevel(logging.INFO) @@ -187,7 +191,7 @@ self.assertEqual("one\nthree\n", stream.getvalue()) def test_preserving_existing_handlers(self): - stream = StringIO() + stream = io.StringIO() self.logger.addHandler(logging.StreamHandler(stream)) self.logger.setLevel(logging.INFO) fixture = LogHandler(self.CustomHandler(), nuke_handlers=False)
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/_fixtures/test_mockpatch.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/_fixtures/test_mockpatch.py
Changed
@@ -13,7 +13,6 @@ # under the License. -import extras import mock # Yes, we only test the rolling backport import testtools
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/_fixtures/test_monkeypatch.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/_fixtures/test_monkeypatch.py
Changed
@@ -14,6 +14,7 @@ # limitations under that license. import functools +import sys import testtools from testtools.matchers import Is @@ -22,6 +23,10 @@ reference = 23 +NEW_PY39_CLASSMETHOD = ( + sys.version_info:2 in ((3, 9), (3,10)) + and not hasattr(sys, "pypy_version_info")) + class C(object): def foo(self, arg): return arg @@ -32,7 +37,7 @@ class D(object): def bar(self): pass - def bar_two_args(self, arg): + def bar_two_args(self, arg=None): return (self, arg) @classmethod def bar_cls(cls): @@ -188,14 +193,27 @@ 'fixtures.tests._fixtures.test_monkeypatch.C.foo_cls', D.bar_cls_args) with fixture: - cls, target_class = C.foo_cls() - self.expectThat(cls, Is(D)) - self.expectThat(target_class, Is(C)) - cls, target_class = C().foo_cls() - self.expectThat(cls, Is(D)) - self.expectThat(target_class, Is(C)) - self._check_restored_static_or_class_method(oldmethod, oldmethod_inst, - C, 'foo_cls') + # Python 3.9 changes the behavior of the classmethod decorator so + # that it now honours the descriptor binding protocol 1. + # This means we're now going to call the monkeypatched classmethod + # the way we would have if it hadn't been monkeypatched: simply + # with the class + # + # https://bugs.python.org/issue19072 + if NEW_PY39_CLASSMETHOD: + cls, = C.foo_cls() + self.expectThat(cls, Is(D)) + cls, = C().foo_cls() + self.expectThat(cls, Is(D)) + else: + cls, target_class = C.foo_cls() + self.expectThat(cls, Is(D)) + self.expectThat(target_class, Is(C)) + cls, target_class = C().foo_cls() + self.expectThat(cls, Is(D)) + self.expectThat(target_class, Is(C)) + self._check_restored_static_or_class_method( + oldmethod, oldmethod_inst, C, 'foo_cls') def test_patch_classmethod_with_function(self): oldmethod = C.foo_cls @@ -222,12 +240,20 @@ with fixture: slf, cls = C.foo_cls() self.expectThat(slf, Is(d)) - self.expectThat(cls, Is(C)) + # See note in test_patch_classmethod_with_classmethod on changes in + # Python 3.9 + if NEW_PY39_CLASSMETHOD: + self.expectThat(cls, Is(None)) + else: + self.expectThat(cls, Is(C)) slf, cls = C().foo_cls() self.expectThat(slf, Is(d)) - self.expectThat(cls, Is(C)) - self._check_restored_static_or_class_method(oldmethod, oldmethod_inst, - C, 'foo_cls') + if NEW_PY39_CLASSMETHOD: + self.expectThat(cls, Is(None)) + else: + self.expectThat(cls, Is(C)) + self._check_restored_static_or_class_method( + oldmethod, oldmethod_inst, C, 'foo_cls') def test_patch_function_with_staticmethod(self): oldmethod = fake_no_args
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/_fixtures/test_popen.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/_fixtures/test_popen.py
Changed
@@ -1,25 +1,24 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # license you chose for the specific language governing permissions and # limitations under that license. +import inspect +import io import subprocess +import sys import testtools -from testtools.compat import ( - _b, - BytesIO, - ) from fixtures import FakePopen, TestWithFixtures from fixtures._fixtures.popen import FakeProcess @@ -41,8 +40,13 @@ fixture = self.useFixture(FakePopen()) proc = fixture('foo', 'bar', 1, None, 'in', 'out', 'err') self.assertEqual(1, len(fixture.procs)) - self.assertEqual(dict(args='foo', 'bar', bufsize=1, executable=None, - stdin='in', stdout='out', stderr='err'), proc._args) + self.assertEqual( + dict( + args='foo', 'bar', bufsize=1, executable=None, + stdin='in', stdout='out', stderr='err', + ), + proc._args, + ) def test_inject_content_stdout(self): def get_info(args): @@ -51,18 +55,112 @@ proc = fixture('foo') self.assertEqual('stdout', proc.stdout) - def test_handles_all_2_7_args(self): + def test_handles_all_Popen_args(self): all_args = dict( args="args", bufsize="bufsize", executable="executable", stdin="stdin", stdout="stdout", stderr="stderr", preexec_fn="preexec_fn", close_fds="close_fds", shell="shell", cwd="cwd", env="env", universal_newlines="universal_newlines", - startupinfo="startupinfo", creationflags="creationflags") + startupinfo="startupinfo", creationflags="creationflags", + restore_signals="restore_signals", + start_new_session="start_new_session", pass_fds="pass_fds", + encoding="encoding", errors="errors") + if sys.version_info >= (3, 7): + all_args"text" = "text" + if sys.version_info >= (3, 9): + all_args"group" = "group" + all_args"extra_groups" = "extra_groups" + all_args"user" = "user" + all_args"umask" = "umask" + if sys.version_info >= (3, 10): + all_args"pipesize" = "pipesize" + if sys.version_info >= (3, 11): + all_args"process_group" = "process_group" + def get_info(proc_args): self.assertEqual(all_args, proc_args) return {} + fixture = self.useFixture(FakePopen(get_info)) - proc = fixture(**all_args) + fixture(**all_args) + + @testtools.skipUnless( + sys.version_info < (3, 7), "only relevant on Python <3.7") + def test_rejects_3_7_args_on_older_versions(self): + fixture = self.useFixture(FakePopen(lambda proc_args: {})) + with testtools.ExpectedException( + TypeError, r".* got an unexpected keyword argument 'text'"): + fixture(args="args", text=True) + + @testtools.skipUnless( + sys.version_info < (3, 9), "only relevant on Python <3.9") + def test_rejects_3_9_args_on_older_versions(self): + fixture = self.useFixture(FakePopen(lambda proc_args: {})) + for arg_name in ("group", "extra_groups", "user", "umask"): + kwargs = {arg_name: arg_name} + expected_message = ( + r".* got an unexpected keyword argument '{}'".format(arg_name)) + with testtools.ExpectedException(TypeError, expected_message): + fixture(args="args", **kwargs) + + @testtools.skipUnless( + sys.version_info < (3, 10), "only relevant on Python <3.10") + def test_rejects_3_10_args_on_older_versions(self): + fixture = self.useFixture(FakePopen(lambda proc_args: {})) + with testtools.ExpectedException( + TypeError, + r".* got an unexpected keyword argument 'pipesize'"): + fixture(args="args", pipesize=1024) + + @testtools.skipUnless( + sys.version_info < (3, 11), "only relevant on Python <3.11") + def test_rejects_3_11_args_on_older_versions(self): + fixture = self.useFixture(FakePopen(lambda proc_args: {})) + with testtools.ExpectedException( + TypeError, + r".* got an unexpected keyword argument 'process_group'"): + fixture(args="args", process_group=42) + + def test_function_signature(self): + fake_signature = inspect.getfullargspec(FakePopen.__call__) + real_signature = inspect.getfullargspec(subprocess.Popen) + + # compare args + + fake_args = fake_signature.args + real_args = real_signature.args + + self.assertListEqual( + fake_args, + real_args, + "Function signature of FakePopen doesn't match subprocess.Popen", + ) + + # compare kw-only args; order doesn't matter so we use a set + + fake_kwargs = set(fake_signature.kwonlyargs) + real_kwargs = set(real_signature.kwonlyargs) + + if sys.version_info < (3, 11): + fake_kwargs.remove('process_group') + + if sys.version_info < (3, 10): + fake_kwargs.remove('pipesize') + + if sys.version_info < (3, 9): + fake_kwargs.remove('group') + fake_kwargs.remove('extra_groups') + fake_kwargs.remove('user') + fake_kwargs.remove('umask') + + if sys.version_info < (3, 7): + fake_kwargs.remove('text') + + self.assertSetEqual( + fake_kwargs, + real_kwargs, + "Function signature of FakePopen doesn't match subprocess.Popen", + ) def test_custom_returncode(self): def get_info(proc_args): @@ -73,9 +171,10 @@ self.assertEqual(1, proc.returncode) def test_with_popen_custom(self): - fixture = self.useFixture(FakePopen()) + self.useFixture(FakePopen()) with subprocess.Popen('ls -lh') as proc: self.assertEqual(None, proc.returncode) + self.assertEqual('ls -lh', proc.args) class TestFakeProcess(testtools.TestCase): @@ -91,14 +190,45 @@ self.assertEqual(0, proc.returncode) def test_communicate_with_out(self): - proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) - self.assertEqual((_b('foo'), ''), proc.communicate()) + proc = FakeProcess({}, {'stdout': io.BytesIO(b'foo')}) + self.assertEqual((b'foo', ''), proc.communicate()) self.assertEqual(0, proc.returncode) + def test_communicate_with_input(self): + proc = FakeProcess({}, {'stdout': io.BytesIO(b'foo')}) + self.assertEqual((b'foo', ''), proc.communicate(input=b'bar')) + + def test_communicate_with_input_and_stdin(self): + stdin = io.BytesIO() + proc = FakeProcess({}, {'stdin': stdin}) + proc.communicate(input=b'hello') + self.assertEqual(b'hello', stdin.getvalue()) + + def test_communicate_with_timeout(self): + proc = FakeProcess({}, {'stdout': io.BytesIO(b'foo')}) + self.assertEqual((b'foo', ''), proc.communicate(timeout=10)) + + def test_args(self):
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/_fixtures/test_pythonpackage.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/_fixtures/test_pythonpackage.py
Changed
@@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -16,7 +16,6 @@ import os.path import testtools -from testtools.compat import _b from fixtures import PythonPackage, TestWithFixtures @@ -32,7 +31,7 @@ fixture.cleanUp() def test_writes_package(self): - fixture = PythonPackage('foo', ('bar.py', _b('woo'))) + fixture = PythonPackage('foo', ('bar.py', b'woo')) fixture.setUp() try: self.assertEqual('', open(os.path.join(fixture.base, 'foo', @@ -43,7 +42,7 @@ fixture.cleanUp() def test_no__init__(self): - fixture = PythonPackage('foo', ('bar.py', _b('woo')), init=False) + fixture = PythonPackage('foo', ('bar.py', b'woo'), init=False) fixture.setUp() try: self.assertFalse(os.path.exists(os.path.join(fixture.base, 'foo',
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/_fixtures/test_streams.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/_fixtures/test_streams.py
Changed
@@ -14,10 +14,6 @@ # limitations under that license. from testtools import TestCase -from testtools.compat import ( - _b, - _u, - ) from testtools.matchers import Contains from fixtures import ( @@ -40,7 +36,7 @@ fixture = ByteStream(detail_name) with fixture: content = fixture.getDetails()detail_name - self.assertEqual(_u(""), content.as_text()) + self.assertEqual("", content.as_text()) def test_stream_content_in_details(self): detail_name = 'test' @@ -49,7 +45,7 @@ stream = fixture.stream content = fixture.getDetails()detail_name # Output after getDetails is called is included. - stream.write(_b("testing 1 2 3")) + stream.write(b"testing 1 2 3") self.assertEqual("testing 1 2 3", content.as_text()) def test_stream_content_reset(self): @@ -58,15 +54,15 @@ with fixture: stream = fixture.stream content = fixture.getDetails()detail_name - stream.write(_b("testing 1 2 3")) + stream.write(b"testing 1 2 3") with fixture: # The old content object returns the old usage - self.assertEqual(_u("testing 1 2 3"), content.as_text()) + self.assertEqual("testing 1 2 3", content.as_text()) content = fixture.getDetails()detail_name # A new fixture returns the new output: stream = fixture.stream - stream.write(_b("1 2 3 testing")) - self.assertEqual(_u("1 2 3 testing"), content.as_text()) + stream.write(b"1 2 3 testing") + self.assertEqual("1 2 3 testing", content.as_text()) class TestStringStreams(TestCase): @@ -76,7 +72,7 @@ fixture = StringStream(detail_name) with fixture: content = fixture.getDetails()detail_name - self.assertEqual(_u(""), content.as_text()) + self.assertEqual("", content.as_text()) def test_stream_content_in_details(self): detail_name = 'test' @@ -85,7 +81,7 @@ stream = fixture.stream content = fixture.getDetails()detail_name # Output after getDetails is called is included. - stream.write(_u("testing 1 2 3")) + stream.write("testing 1 2 3") self.assertEqual("testing 1 2 3", content.as_text()) def test_stream_content_reset(self): @@ -94,12 +90,12 @@ with fixture: stream = fixture.stream content = fixture.getDetails()detail_name - stream.write(_u("testing 1 2 3")) + stream.write("testing 1 2 3") with fixture: # The old content object returns the old usage - self.assertEqual(_u("testing 1 2 3"), content.as_text()) + self.assertEqual("testing 1 2 3", content.as_text()) content = fixture.getDetails()detail_name # A new fixture returns the new output: stream = fixture.stream - stream.write(_u("1 2 3 testing")) - self.assertEqual(_u("1 2 3 testing"), content.as_text()) + stream.write("1 2 3 testing") + self.assertEqual("1 2 3 testing", content.as_text())
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/fixtures/tests/test_fixture.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/fixtures/tests/test_fixture.py
Changed
@@ -1,12 +1,12 @@ # fixtures: Fixtures with cleanups for testing and convenience. # # Copyright (c) 2010, Robert Collins <robertc@robertcollins.net> -# +# # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -268,7 +268,7 @@ self.addCleanup(log.append, 'cleaned') raise MyBase('fred') f = Subclass() - e = self.assertRaises(MyBase, f.setUp) + self.assertRaises(MyBase, f.setUp) self.assertRaises(TypeError, f.cleanUp) self.assertEqual('cleaned', log)
View file
_service:tar_scm:fixtures-4.0.1.tar.gz/pyproject.toml
Added
@@ -0,0 +1,3 @@ +build-system +requires = "pbr>=5.7.0", "setuptools>=36.6.0", "wheel" +build-backend = "pbr.build"
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/requirements.txt -> _service:tar_scm:fixtures-4.0.1.tar.gz/requirements.txt
Changed
@@ -1,3 +1,1 @@ -pbr>=0.11 -six -testtools>=0.9.22 +pbr>=5.7.0
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/setup.cfg -> _service:tar_scm:fixtures-4.0.1.tar.gz/setup.cfg
Changed
@@ -1,37 +1,40 @@ metadata name = fixtures summary = Fixtures, reusable state for writing clean tests and more. -description-file = - README +description_file = + README.rst +description_content_type = text/x-rst; charset=UTF-8 author = Robert Collins -author-email = robertc@robertcollins.net -home-page = https://launchpad.net/python-fixtures -classifier = - Development Status :: 6 - Mature - Intended Audience :: Developers - License :: OSI Approved :: BSD License - License :: OSI Approved :: Apache Software License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Topic :: Software Development :: Quality Assurance - Topic :: Software Development :: Testing +author_email = robertc@robertcollins.net +url = https://github.com/testing-cabal/fixtures +python_requires = >=3.6 +classifiers = + Development Status :: 6 - Mature + Intended Audience :: Developers + License :: OSI Approved :: BSD License + License :: OSI Approved :: Apache Software License + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy + Topic :: Software Development :: Quality Assurance + Topic :: Software Development :: Testing files -packages = - fixtures - -bdist_wheel -universal = 1 +packages = + fixtures extras -test = - mock -docs = - docutils - -egg_info -tag_build = -tag_date = 0 -tag_svn_revision = 0 - +streams = + testtools +test = + mock + testtools +docs = + docutils
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/setup.py -> _service:tar_scm:fixtures-4.0.1.tar.gz/setup.py
Changed
@@ -3,5 +3,6 @@ import setuptools setuptools.setup( - setup_requires='pbr>0.11', - pbr=True) + setup_requires='pbr>5.7.0', + pbr=True, +)
View file
_service:tar_scm:fixtures-3.0.0.tar.gz/tox.ini -> _service:tar_scm:fixtures-4.0.1.tar.gz/tox.ini
Changed
@@ -1,12 +1,10 @@ tox -envlist = py26,py27,py32,py33,py34,py35,pypy,pypy3 -minversion = 1.6 -skipsdist = True +envlist = py36,py37,py38,py39,py310,py311,pypy3 +minversion = 3.1 testenv -usedevelop = True -install_command = pip install -U {opts} {packages} -setenv = VIRTUAL_ENV={envdir} -whitelist_externals = make -deps = .docs,test -commands = make check +usedevelop = true +extras = + docs + test +commands = python -m testtools.run fixtures.test_suite
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2