Skip to content

Commit

Permalink
Merge pull request #77 from stephenfin/trivial
Browse files Browse the repository at this point in the history
Fix errant docstring, formatting
  • Loading branch information
jelmer authored Sep 1, 2023
2 parents 30b2066 + 7e9120c commit bdc287c
Show file tree
Hide file tree
Showing 35 changed files with 513 additions and 290 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9402d8dcdf7b0a1a1e004f56b7bcfc0070fa9f60
8 changes: 5 additions & 3 deletions fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
# Otherwise it is major.minor.micro~$(revno).
from pbr.version import VersionInfo

_version = VersionInfo('fixtures')
__version__ = _version.semantic_version().version_tuple()
version = _version.release_string()
Expand Down Expand Up @@ -76,7 +77,7 @@
'WarningsFilter',
'__version__',
'version',
]
]


from fixtures.fixture import (
Expand All @@ -86,7 +87,7 @@
MethodFixture,
MultipleExceptions,
SetupError,
)
)
from fixtures._fixtures import (
ByteStream,
DetailStream,
Expand All @@ -112,12 +113,13 @@
TimeoutException,
WarningsCapture,
WarningsFilter,
)
)
from fixtures.testcase import TestWithFixtures


def test_suite():
import fixtures.tests

return fixtures.tests.test_suite()


Expand Down
22 changes: 11 additions & 11 deletions fixtures/_fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
# Copyright (c) 2010, 2011, Robert Collins <[email protected]>
#
#
# 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
Expand Down Expand Up @@ -47,42 +47,42 @@
from fixtures._fixtures.environ import (
EnvironmentVariable,
EnvironmentVariableFixture,
)
)
from fixtures._fixtures.logger import (
FakeLogger,
LoggerFixture,
LogHandler,
)
)
from fixtures._fixtures.mockpatch import (
MockPatch,
MockPatchMultiple,
MockPatchObject,
)
)
from fixtures._fixtures.monkeypatch import MonkeyPatch
from fixtures._fixtures.popen import (
FakePopen,
PopenFixture,
)
)
from fixtures._fixtures.packagepath import PackagePathEntry
from fixtures._fixtures.pythonpackage import PythonPackage
from fixtures._fixtures.pythonpath import PythonPathEntry
from fixtures._fixtures.streams import (
ByteStream,
DetailStream,
StringStream,
)
)
from fixtures._fixtures.tempdir import (
NestedTempfile,
TempDir,
)
)
from fixtures._fixtures.temphomedir import (
TempHomeDir,
)
)
from fixtures._fixtures.timeout import (
Timeout,
TimeoutException,
)
)
from fixtures._fixtures.warnings import (
WarningsCapture,
WarningsFilter,
)
)
4 changes: 2 additions & 2 deletions fixtures/_fixtures/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

__all__ = [
'EnvironmentVariable',
'EnvironmentVariableFixture'
]
'EnvironmentVariableFixture',
]

import os

Expand Down
25 changes: 19 additions & 6 deletions fixtures/_fixtures/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'FakeLogger',
'LoggerFixture',
'LogHandler',
]
]


class LogHandler(Fixture):
Expand Down Expand Up @@ -62,6 +62,7 @@ def _setUp(self):

class StreamHandlerRaiseException(StreamHandler):
"""Handler class that will raise an exception on formatting errors."""

def handleError(self, record):
_, value, tb = sys.exc_info()
raise value.with_traceback(tb)
Expand All @@ -70,8 +71,15 @@ def handleError(self, record):
class FakeLogger(Fixture):
"""Replace a logger and capture its output."""

def __init__(self, name="", level=INFO, format=None,
datefmt=None, nuke_handlers=True, formatter=None):
def __init__(
self,
name="",
level=INFO,
format=None,
datefmt=None,
nuke_handlers=True,
formatter=None,
):
"""Create a FakeLogger fixture.
:param name: The name of the logger to replace. Defaults to "".
Expand Down Expand Up @@ -106,11 +114,16 @@ def _setUp(self):
self._output = output
handler = StreamHandlerRaiseException(output)
if self._format:
formatter = (self._formatter or Formatter)
formatter = self._formatter or Formatter
handler.setFormatter(formatter(self._format, self._datefmt))
self.useFixture(
LogHandler(handler, name=self._name, level=self._level,
nuke_handlers=self._nuke_handlers))
LogHandler(
handler,
name=self._name,
level=self._level,
nuke_handlers=self._nuke_handlers,
)
)

@property
def output(self):
Expand Down
7 changes: 4 additions & 3 deletions fixtures/_fixtures/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under that license.

__all__ = [
'MonkeyPatch'
'MonkeyPatch',
]

import functools
Expand All @@ -23,7 +23,7 @@
from fixtures import Fixture


_class_types = (type, )
_class_types = (type,)


def _coerce_values(obj, name, new_value, sentinel):
Expand Down Expand Up @@ -144,7 +144,8 @@ def _setUp(self):
current = getattr(current, component)
sentinel = object()
new_value, old_value = _coerce_values(
current, attribute, self.new_value, sentinel)
current, attribute, self.new_value, sentinel
)

if self.new_value is self.delete:
if old_value is not sentinel:
Expand Down
8 changes: 4 additions & 4 deletions fixtures/_fixtures/packagepath.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
# Copyright (c) 2011, Robert Collins <[email protected]>
#
#
# 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.

__all__ = [
'PackagePathEntry'
]
'PackagePathEntry',
]

import sys

Expand Down
101 changes: 74 additions & 27 deletions fixtures/_fixtures/popen.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
# Copyright (c) 2010, 2011, Robert Collins <[email protected]>
#
#
# 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
Expand All @@ -15,8 +15,8 @@

__all__ = [
'FakePopen',
'PopenFixture'
]
'PopenFixture',
]

import random
import subprocess
Expand Down Expand Up @@ -90,7 +90,7 @@ class FakePopen(Fixture):

_unpassed = object()

def __init__(self, get_info=lambda _:{}):
def __init__(self, get_info=lambda _: {}):
"""Create a PopenFixture
:param get_info: Optional callback to control the behaviour of the
Expand All @@ -100,7 +100,7 @@ def __init__(self, get_info=lambda _:{}):
dict, making it possible to detect the difference between 'passed
with a default value' and 'not passed at all'.
e.g.
e.g.
def get_info(proc_args):
self.assertEqual(subprocess.PIPE, proc_args['stdin'])
return {'stdin': StringIO('foobar')}
Expand All @@ -123,47 +123,94 @@ def _setUp(self):

# The method has the correct signature so we error appropriately if called
# wrongly.
def __call__(self, args, bufsize=_unpassed, executable=_unpassed,
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,
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):
def __call__(
self,
args,
bufsize=_unpassed,
executable=_unpassed,
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,
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'")
"'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))
"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:
"'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'")
"'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",
"restore_signals", "start_new_session", "pass_fds", "group",
"extra_groups", "user", "umask", "encoding", "errors", "text",
"pipesize", "process_group"]:
"bufsize",
"executable",
"stdin",
"stdout",
"stderr",
"preexec_fn",
"close_fds",
"shell",
"cwd",
"env",
"universal_newlines",
"startupinfo",
"creationflags",
"restore_signals",
"start_new_session",
"pass_fds",
"group",
"extra_groups",
"user",
"umask",
"encoding",
"errors",
"text",
"pipesize",
"process_group",
]:
if local[param] is not FakePopen._unpassed:
proc_args[param] = local[param]
proc_info = self.get_info(proc_args)
Expand Down
Loading

0 comments on commit bdc287c

Please sign in to comment.