Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-testpath for openSUSE:Factory
checked in at 2021-10-25 15:17:08
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-testpath (Old)
and /work/SRC/openSUSE:Factory/.python-testpath.new.1890 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-testpath"
Mon Oct 25 15:17:08 2021 rev:9 rq:926608 version:0.5.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-testpath/python-testpath.changes
2019-11-22 10:23:39.469304799 +0100
+++
/work/SRC/openSUSE:Factory/.python-testpath.new.1890/python-testpath.changes
2021-10-25 15:17:44.101686948 +0200
@@ -1,0 +2,11 @@
+Wed Oct 20 16:23:05 UTC 2021 - Ben Greiner <[email protected]>
+
+- Update to version 0.5.0
+* Easier ways to use `MockCommand` to customise mocked commands,
+ including `python=` to specify extra code to run,
+ `.MockCommand.fixed_output`, and `.MockCommand.assert_called`.
+* Command mocking will use `os.defpath` as the initial PATH if the
+ PATH environment variable is not set.
+- Drop Python 2 build
+
+-------------------------------------------------------------------
Old:
----
testpath-0.4.4.tar.gz
New:
----
testpath-0.5.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-testpath.spec ++++++
--- /var/tmp/diff_new_pack.YNezjy/_old 2021-10-25 15:17:44.605687263 +0200
+++ /var/tmp/diff_new_pack.YNezjy/_new 2021-10-25 15:17:44.605687263 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-testpath
#
-# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -16,16 +16,18 @@
#
-%{?!python_module:%define python_module() python-%{**} python3-%{**}}
+%{?!python_module:%define python_module() python3-%{**}}
+%define skip_python2 1
Name: python-testpath
-Version: 0.4.4
+Version: 0.5.0
Release: 0
Summary: Test utilities for code working with files and commands
-License: LGPL-2.1-or-later OR BSD-3-Clause
+License: BSD-3-Clause OR LGPL-2.1-or-later
Group: Development/Languages/Python
-Url: https://github.com/jupyter/testpath
+URL: https://github.com/jupyter/testpath
Source0:
https://files.pythonhosted.org/packages/source/t/testpath/testpath-%{version}.tar.gz
BuildRequires: %{python_module pytest}
+BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
BuildArch: noarch
@@ -51,12 +53,12 @@
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%check
-%python_exec -m pytest
+%pytest
%files %{python_files}
%doc README.rst
%license LICENSE
%{python_sitelib}/testpath/
-%{python_sitelib}/testpath-%{version}-py*.egg-info
+%{python_sitelib}/testpath-%{version}*-info
%changelog
++++++ testpath-0.4.4.tar.gz -> testpath-0.5.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/.github/workflows/test.yml
new/testpath-0.5.0/.github/workflows/test.yml
--- old/testpath-0.4.4/.github/workflows/test.yml 1970-01-01
01:00:00.000000000 +0100
+++ new/testpath-0.5.0/.github/workflows/test.yml 2021-05-17
11:27:52.053410800 +0200
@@ -0,0 +1,25 @@
+name: Test
+
+on: [push, pull_request]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ python-version: [ 3.5, 3.6, 3.7, 3.8, 3.9, ]
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Setup Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v2
+ with:
+ python-version: ${{ matrix.python-version }}
+
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install '.[test]'
+
+ - name: Run tests
+ run: pytest
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/.travis.yml
new/testpath-0.5.0/.travis.yml
--- old/testpath-0.4.4/.travis.yml 2019-11-04 14:46:06.502248500 +0100
+++ new/testpath-0.5.0/.travis.yml 1970-01-01 01:00:00.000000000 +0100
@@ -1,16 +0,0 @@
-language: python
-python:
- - "3.8"
- - "3.7"
- - "3.6"
- - "3.5"
- - "3.4"
- - "2.7"
-
-# command to run tests
-script: py.test
-
-install: if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install pathlib2; fi
-
-# Enable new Travis stack, should speed up builds
-sudo: false
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/PKG-INFO new/testpath-0.5.0/PKG-INFO
--- old/testpath-0.4.4/PKG-INFO 1970-01-01 01:00:00.000000000 +0100
+++ new/testpath-0.5.0/PKG-INFO 1970-01-01 01:00:00.000000000 +0100
@@ -1,7 +1,7 @@
Metadata-Version: 1.1
Name: testpath
-Version: 0.4.4
+Version: 0.5.0
Summary: Test utilities for code working with files and commands
-Home-page: https://github.com/jupyter/testpath
-Author: Jupyter Development Team
-Author-email: [email protected]
+Home-page: None
+Author: None
+Author-email: Jupyter Development Team <[email protected]>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/doc/commands.rst
new/testpath-0.5.0/doc/commands.rst
--- old/testpath-0.4.4/doc/commands.rst 2017-08-20 15:25:13.474373800 +0200
+++ new/testpath-0.5.0/doc/commands.rst 2021-05-17 12:56:21.033990000 +0200
@@ -1,28 +1,34 @@
Mocking system commands
=======================
+.. currentmodule:: testpath
+
Mocking is a technique to replace parts of a system with interfaces that don't
do anything, but which your tests can check whether and how they were called.
The :mod:`unittest.mock` module in Python 3 lets you mock Python functions and
-classes. These tools let you mock external commands.
+classes. The tools described here let you mock external commands.
Commands are mocked by creating a real file in a temporary directory which is
added to the :envvar:`PATH` environment variable, not by replacing Python
-functions. So if you mock ``foo``, and your Python code runs a shell script
-which calls ``foo``, it will be the mocked command that it runs.
+functions. So if you mock ``git``, and your Python code runs a shell script
+which calls ``git``, it will be the mocked command that it runs.
By default, mocked commands record each call made to them, so that your test
can
-check these. Using the :class:`MockCommand` API, you can mock a command to do
-something else.
+check these. Using the :class:`MockCommand` API, you can change what a mocked
+command does.
.. note::
- These tools work by changing global state. They're not safe to use if
- commands may be called from multiple threads or coroutines.
-
-.. currentmodule:: testpath
+ Mocking a command affects all running threads or coroutines in a program.
+ There's no way to mock a command for only the current thread/coroutine,
+ because it uses environment variables, which are global.
.. autofunction:: assert_calls
.. autoclass:: MockCommand
- :members: get_calls
+
+ .. automethod:: fixed_output
+
+ .. automethod:: get_calls
+
+ .. automethod:: assert_called
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/doc/conf.py
new/testpath-0.5.0/doc/conf.py
--- old/testpath-0.4.4/doc/conf.py 2019-11-04 19:01:29.458482000 +0100
+++ new/testpath-0.5.0/doc/conf.py 2021-05-17 12:06:25.630652000 +0200
@@ -263,4 +263,4 @@
# configuration for intersphinx: refer to the Python standard library.
-intersphinx_mapping = {'python': ('http://docs.python.org/3', None)}
+intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/doc/history.rst
new/testpath-0.5.0/doc/history.rst
--- old/testpath-0.4.4/doc/history.rst 1970-01-01 01:00:00.000000000 +0100
+++ new/testpath-0.5.0/doc/history.rst 2021-05-17 12:23:25.380330600 +0200
@@ -0,0 +1,13 @@
+Release notes
+=============
+
+0.5
+---
+
+* Easier ways to use :class:`.MockCommand` to customise mocked commands,
+ including ``python=`` to specify extra code to run,
+ :meth:`~.MockCommand.fixed_output`, and :meth:`~.MockCommand.assert_called`.
+* Command mocking will use :data:`os.defpath` as the initial PATH if the PATH
+ environment variable is not set.
+
+May 2021
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/doc/index.rst
new/testpath-0.5.0/doc/index.rst
--- old/testpath-0.4.4/doc/index.rst 2017-08-20 15:25:13.474373800 +0200
+++ new/testpath-0.5.0/doc/index.rst 2021-05-17 12:03:41.366711000 +0200
@@ -18,6 +18,11 @@
env
tempdir
+.. toctree::
+ :maxdepth: 1
+
+ history
+
Indices and tables
==================
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/pyproject.toml
new/testpath-0.5.0/pyproject.toml
--- old/testpath-0.4.4/pyproject.toml 2018-10-02 08:30:55.218157500 +0200
+++ new/testpath-0.5.0/pyproject.toml 2021-05-17 11:27:52.054411000 +0200
@@ -1,24 +1,26 @@
[build-system]
-requires = ["flit"]
-build-backend = "flit.buildapi"
+requires = ["flit_core >=3.2.0,<3.3"]
+build-backend = "flit_core.buildapi"
-[tool.flit.metadata]
-module = "testpath"
-author = "Jupyter Development Team"
-author-email = "[email protected]"
-home-page = "https://github.com/jupyter/testpath"
-description-file = "README.rst"
+[project]
+name = "testpath"
+authors = [
+ {name="Jupyter Development Team", email="[email protected]"},
+]
+readme = "README.rst"
+requires-python = ">= 3.5"
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
- "Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Testing",
]
+dynamic = ["version", "description"]
-[tool.flit.metadata.requires-extra]
-test = ["pathlib2; python_version == \"2.7\""]
+[project.optional-dependencies]
+test = ["pytest", "pathlib2; python_version == \"2.7\""]
-[tool.flit.metadata.urls]
+[project.urls]
Documentation = "https://testpath.readthedocs.io/en/latest/"
+Source = "https://github.com/jupyter/testpath"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/setup.py new/testpath-0.5.0/setup.py
--- old/testpath-0.4.4/setup.py 1970-01-01 01:00:00.000000000 +0100
+++ new/testpath-0.5.0/setup.py 1970-01-01 01:00:00.000000000 +0100
@@ -10,15 +10,16 @@
{'': ['*']}
extras_require = \
-{'test:python_version == "2.7"': ['pathlib2']}
+{'test': ['pytest'], 'test:python_version == "2.7"': ['pathlib2']}
setup(name='testpath',
- version='0.4.4',
+ version='0.5.0',
description='Test utilities for code working with files and commands',
- author='Jupyter Development Team',
- author_email='[email protected]',
- url='https://github.com/jupyter/testpath',
+ author=None,
+ author_email='Jupyter Development Team <[email protected]>',
+ url=None,
packages=packages,
package_data=package_data,
extras_require=extras_require,
+ python_requires='>= 3.5',
)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/testpath/__init__.py
new/testpath-0.5.0/testpath/__init__.py
--- old/testpath-0.4.4/testpath/__init__.py 2019-11-04 19:01:29.438482000
+0100
+++ new/testpath-0.5.0/testpath/__init__.py 2021-05-17 12:57:24.185321000
+0200
@@ -3,4 +3,4 @@
from .env import temporary_env, modified_env, make_env_restorer
from .commands import MockCommand, assert_calls
-__version__ = '0.4.4'
+__version__ = '0.5.0'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/testpath/commands.py
new/testpath-0.5.0/testpath/commands.py
--- old/testpath-0.4.4/testpath/commands.py 2018-09-27 22:15:03.638236800
+0200
+++ new/testpath-0.5.0/testpath/commands.py 2021-05-17 12:18:20.537747600
+0200
@@ -11,8 +11,17 @@
recording_dir = None
+def _make_recording_file(prefix):
+ """Make a temp file for recording calls to a mocked command"""
+ global recording_dir
+ if recording_dir is None:
+ recording_dir = tempfile.mkdtemp()
+ fd, p = tempfile.mkstemp(dir=recording_dir, prefix=prefix, suffix='.json')
+ os.close(fd)
+ return p
+
def prepend_to_path(dir):
- os.environ['PATH'] = dir + os.pathsep + os.environ['PATH']
+ os.environ['PATH'] = dir + os.pathsep + os.environ.get('PATH', os.defpath)
def remove_from_path(dir):
path_dirs = os.environ['PATH'].split(os.pathsep)
@@ -30,6 +39,14 @@
'cwd': os.getcwd()}},
f)
f.write('\\x1e') # ASCII record separator
+
+{extra_code}
+"""
+
+_output_template = """\
+sys.stdout.write({!r})
+sys.stderr.write({!r})
+sys.exit({!r})
"""
# TODO: Overlapping calls to the same command may interleave writes.
@@ -39,25 +56,52 @@
The mock command will be written to a directory at the front of $PATH,
taking precedence over any existing command with the same name.
-
- By specifying content as a string, you can determine what running the
- command will do. The default content records each time the command is
- called and exits: you can access these records with mockcmd.get_calls().
-
- On Windows, the specified content will be run by the Python interpreter in
- use. On Unix, it should start with a shebang (``#!/path/to/interpreter``).
+
+ The *python* parameter accepts a string of code for the command to run,
+ in addition to the default behaviour of recording calls to the command.
+ This will run with the same Python interpreter as the calling code, but in
+ a new process.
+
+ The *content* parameter gives extra control, by providing a script which
+ will run with no additions. On Unix, it should start with a shebang (e.g.
+ ``#!/usr/bin/env python``) specifying the interpreter. On Windows, it will
+ always be run by the same Python interpreter as the calling code.
+ Calls to the command will not be recorded when content is specified.
"""
- def __init__(self, name, content=None):
- global recording_dir
+ def __init__(self, name, content=None, python=''):
self.name = name
+ self.recording_file = _make_recording_file(prefix=name)
+ self.command_dir = tempfile.mkdtemp()
+
+ if content is None:
+ content = _record_run.format(
+ python=sys.executable, recording_file=self.recording_file,
+ extra_code=python,
+ )
+ elif python:
+ raise ValueError(
+ "Specify script content or extra code (python='...'), not both"
+ )
self.content = content
- if recording_dir is None:
- recording_dir = tempfile.mkdtemp()
- fd, self.recording_file = tempfile.mkstemp(dir=recording_dir,
- prefix=name, suffix='.json')
- os.close(fd)
- self.command_dir = tempfile.mkdtemp()
+ @classmethod
+ def fixed_output(cls, name, stdout='', stderr='', exit_status=0):
+ """Make a mock command, producing fixed output when it is run::
+
+ t = 'Sat 24 Apr 17:11:58 BST 2021\\n'
+ with MockCommand.fixed_output('date', t) as mock_date:
+ ...
+
+ The stdout & stderr strings will be written to the respective streams,
+ and the process will exit with the specified numeric status (the
default
+ of 0 indicates success).
+
+ This works with the recording mechanism, so you can check what
arguments
+ this command was called with.
+ """
+ return cls(
+ name, python=_output_template.format(stdout, stderr, exit_status)
+ )
def _copy_exe(self):
bitness = '64' if (sys.maxsize > 2**32) else '32'
@@ -77,10 +121,6 @@
if os.path.isfile(self._cmd_path):
raise EnvironmentError("Command %r already exists at %s" %
(self.name, self._cmd_path))
-
- if self.content is None:
- self.content = _record_run.format(python=sys.executable,
-
recording_file=self.recording_file)
with open(self._cmd_path, 'w') as f:
f.write(self.content)
@@ -101,11 +141,11 @@
def get_calls(self):
"""Get a list of calls made to this mocked command.
- This relies on the default script content, so it will return an
- empty list if you specified a different content parameter.
-
For each time the command was run, the list will contain a dictionary
with keys argv, env and cwd.
+
+ This won't work if you used the *content* parameter to alter what
+ the mocked command does.
"""
if recording_dir is None:
return []
@@ -118,6 +158,32 @@
return [json.loads(c) for c in chunks]
+ def assert_called(self, args=None):
+ """Assert that the mock command has been called at least once.
+
+ If args is passed, also check that it was called at least once with the
+ given arguments (not including the command name), e.g.::
+
+ with MockCommand('rsync') as mock_rsync:
+ function_to_test()
+
+ mock_rsync.assert_called(['/var/log', 'backup-server:logs'])
+
+ This won't work if you used the *content* parameter to alter what
+ the mocked command does.
+ """
+ calls = self.get_calls()
+ assert calls != [], "Command %r was not called" % self.name
+
+ if args is not None:
+ if not any(args == c['argv'][1:] for c in calls):
+ msg = ["Command %r was not called with specified args (%r)" %
+ (self.name, args),
+ "It was called with these arguments: "]
+ for c in calls:
+ msg.append(' %r' % c['argv'][1:])
+ raise AssertionError('\n'.join(msg))
+
@contextlib.contextmanager
def assert_calls(cmd, args=None):
@@ -137,14 +203,4 @@
with MockCommand(cmd) as mc:
yield
- calls = mc.get_calls()
- assert calls != [], "Command %r was not called" % cmd
-
- if args is not None:
- if not any(args == c['argv'][1:] for c in calls):
- msg = ["Command %r was not called with specified args (%r)" %
- (cmd, args),
- "It was called with these arguments: "]
- for c in calls:
- msg.append(' %r' % c['argv'][1:])
- raise AssertionError('\n'.join(msg))
+ mc.assert_called(args=args)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/testpath-0.4.4/tests/test_commands.py
new/testpath-0.5.0/tests/test_commands.py
--- old/testpath-0.4.4/tests/test_commands.py 2017-08-20 15:25:13.477373800
+0200
+++ new/testpath-0.5.0/tests/test_commands.py 2021-05-17 11:27:52.066411000
+0200
@@ -1,5 +1,5 @@
import os
-from subprocess import call
+from subprocess import call, check_output
import unittest
from testpath.commands import *
@@ -34,3 +34,12 @@
with self.assertRaises(AssertionError):
with assert_calls('git'):
pass
+
+def test_fixed_output():
+ t = 'Sat 24 Apr 17:11:58 BST 2021\n'
+ with MockCommand.fixed_output('date', t) as mock_date:
+ stdout = check_output(['date'])
+
+ mock_date.assert_called([])
+ assert len(mock_date.get_calls()) == 1
+ assert stdout.decode('ascii', 'replace') == t