Skip to content
Snippets Groups Projects
Commit b457c2ff authored by SVN-Git Migration's avatar SVN-Git Migration
Browse files

Imported Upstream version 1.3

parent d0e24ff9
No related branches found
No related tags found
No related merge requests found
include README.rst
Metadata-Version: 1.0
Name: ScriptTest
Version: 1.2
Metadata-Version: 1.1
Name: scripttest
Version: 1.3
Summary: Helper to test command-line scripts
Home-page: http://pythonpaste.org/scripttest/
Author: Ian Bicking
Author-email: ianb@colorstudy.com
License: MIT
Description: ScriptTest is a library to help you test your interactive command-line
Description: scripttest
==========
.. image:: https://pypip.in/v/ScriptTest/badge.png
:target: https://pypi.python.org/pypi/scripttest
.. image:: https://secure.travis-ci.org/pypa/scripttest.png
:target: http://travis-ci.org/pypa/scripttest
scripttest is a library to help you test your interactive command-line
applications.
With it you can easily run the command (in a subprocess) and see the
output (stdout, stderr) and any file modifications.
* The `source repository <http://bitbucket.org/ianb/scripttest/>`_.
* The `source repository <https://github.com/pypa/scripttest>`_.
* The `documentation <https://scripttest.readthedocs.org/>`_.
Keywords: test unittest doctest command line scripts
Platform: UNKNOWN
......
scripttest
==========
.. image:: https://pypip.in/v/ScriptTest/badge.png
:target: https://pypi.python.org/pypi/scripttest
.. image:: https://secure.travis-ci.org/pypa/scripttest.png
:target: http://travis-ci.org/pypa/scripttest
scripttest is a library to help you test your interactive command-line
applications.
With it you can easily run the command (in a subprocess) and see the
output (stdout, stderr) and any file modifications.
* The `source repository <https://github.com/pypa/scripttest>`_.
* The `documentation <https://scripttest.readthedocs.org/>`_.
setup.cfg
setup.py
ScriptTest.egg-info/PKG-INFO
ScriptTest.egg-info/SOURCES.txt
ScriptTest.egg-info/dependency_links.txt
ScriptTest.egg-info/top_level.txt
ScriptTest.egg-info/zip-safe
scripttest/__init__.py
scripttest/backwardscompat.py
\ No newline at end of file
Metadata-Version: 1.0
Name: ScriptTest
Version: 1.2
Metadata-Version: 1.1
Name: scripttest
Version: 1.3
Summary: Helper to test command-line scripts
Home-page: http://pythonpaste.org/scripttest/
Author: Ian Bicking
Author-email: ianb@colorstudy.com
License: MIT
Description: ScriptTest is a library to help you test your interactive command-line
Description: scripttest
==========
.. image:: https://pypip.in/v/ScriptTest/badge.png
:target: https://pypi.python.org/pypi/scripttest
.. image:: https://secure.travis-ci.org/pypa/scripttest.png
:target: http://travis-ci.org/pypa/scripttest
scripttest is a library to help you test your interactive command-line
applications.
With it you can easily run the command (in a subprocess) and see the
output (stdout, stderr) and any file modifications.
* The `source repository <http://bitbucket.org/ianb/scripttest/>`_.
* The `source repository <https://github.com/pypa/scripttest>`_.
* The `documentation <https://scripttest.readthedocs.org/>`_.
Keywords: test unittest doctest command line scripts
Platform: UNKNOWN
......
MANIFEST.in
README.rst
scripttest.py
setup.cfg
setup.py
scripttest.egg-info/PKG-INFO
scripttest.egg-info/SOURCES.txt
scripttest.egg-info/dependency_links.txt
scripttest.egg-info/top_level.txt
scripttest.egg-info/zip-safe
\ No newline at end of file
File moved
# (c) 2005-2007 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
# (c) 2005-2007 Ian Bicking and contributors; written for Paste
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license.php
"""
Helpers for testing command-line scripts
"""
......@@ -9,18 +10,32 @@ import shutil
import shlex
import subprocess
import re
from scripttest.backwardscompat import string
import zlib
if sys.platform == 'win32':
def clean_environ(e):
ret = dict(
((str(k),str(v)) for k,v in e.items()) )
((str(k), str(v)) for k, v in e.items()))
return ret
else:
def clean_environ(e):
def clean_environ(e):
return e
# From pathutils by Michael Foord: http://www.voidspace.org.uk/python/pathutils.html
def string(string):
if sys.version_info >= (3,):
if isinstance(string, str):
return string
return str(string, "utf-8")
else:
if isinstance(string, unicode):
return string
return string.decode('utf-8')
# From pathutils by Michael Foord:
# http://www.voidspace.org.uk/python/pathutils.html
def onerror(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.
......@@ -48,11 +63,11 @@ if sys.platform == 'win32':
if os.path.splitext(invoked)[1]:
return invoked
explicit_dir = os.path.dirname(invoked)
if explicit_dir:
path = [ explicit_dir ]
path = [explicit_dir]
else:
path = environ.get('PATH').split(os.path.pathsep)
......@@ -66,26 +81,26 @@ if sys.platform == 'win32':
for dir in path:
for ext in extensions:
full_path = os.path.join(dir, invoked+ext)
if os.path.exists( full_path ):
if os.path.exists(full_path):
return full_path
return invoked # Not found; invoking it will likely fail
return invoked # Not found; invoking it will likely fail
class Popen(subprocess.Popen):
def __init__(
self, args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=False, shell=False,
cwd=None, env=None,
*args_, **kw):
self, args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=False, shell=False,
cwd=None, env=None,
*args_, **kw):
if executable is None and not shell:
executable = full_executable_path(args[0], env or os.environ)
super(Popen,self).__init__(
args, bufsize, executable, stdin, stdout, stderr,
super(Popen, self).__init__(
args, bufsize, executable, stdin, stdout, stderr,
preexec_fn, close_fds, shell, cwd, env, *args_, **kw)
else:
from subprocess import Popen
......@@ -190,7 +205,8 @@ class TestFileEnvironment(object):
``cwd``: (default ``self.cwd``)
The working directory to run in (default ``base_path``)
``quiet``: (default False)
When there's an error (return code != 0), do not print stdout/stderr
When there's an error (return code != 0), do not print
stdout/stderr
Returns a `ProcResult
<class-paste.fixture.ProcResult.html>`_ object.
......@@ -205,7 +221,8 @@ class TestFileEnvironment(object):
if not self.temp_path:
if 'expect_temp' in kw:
raise TypeError(
'You cannot use expect_temp unless you use capture_temp=True')
'You cannot use expect_temp unless you use '
'capture_temp=True')
expect_temp = _popget(kw, 'expect_temp', not self._assert_no_temp)
args = list(map(str, args))
assert not kw, (
......@@ -217,8 +234,7 @@ class TestFileEnvironment(object):
else:
script, args = script.split(None, 1)
args = shlex.split(args)
environ=clean_environ(self.environ)
all = [script] + args
files_before = self._find_files()
......@@ -226,18 +242,20 @@ class TestFileEnvironment(object):
if debug:
proc = subprocess.Popen(all,
cwd=cwd,
shell=(sys.platform=='win32'), # see http://bugs.python.org/issue8557
# see http://bugs.python.org/issue8557
shell=(sys.platform == 'win32'),
env=clean_environ(self.environ))
else:
proc = subprocess.Popen(all, stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
proc = subprocess.Popen(all, stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
cwd=cwd,
shell=(sys.platform=='win32'), # see http://bugs.python.org/issue8557
# see http://bugs.python.org/issue8557
shell=(sys.platform == 'win32'),
env=clean_environ(self.environ))
if debug:
stdout,stderr = proc.communicate()
stdout, stderr = proc.communicate()
else:
stdout, stderr = proc.communicate(stdin)
stdout = string(stdout)
......@@ -294,11 +312,16 @@ class TestFileEnvironment(object):
marker_file = os.path.join(self.base_path, '.scripttest-test-dir.txt')
if os.path.exists(self.base_path):
if not force and not os.path.exists(marker_file):
sys.stderr.write('The directory %s does not appear to have been created by ScriptTest\n' % self.base_path)
sys.stderr.write('The directory %s must be a scratch directory; it will be wiped after every test run\n' % self.base_path)
sys.stderr.write(
'The directory %s does not appear to have been created by '
'ScriptTest\n' % self.base_path)
sys.stderr.write(
'The directory %s must be a scratch directory; it will be '
'wiped after every test run\n' % self.base_path)
sys.stderr.write('Please delete this directory manually\n')
raise AssertionError(
"The directory %s was not created by ScriptTest; it must be deleted manually" % self.base_path)
"The directory %s was not created by ScriptTest; it must "
"be deleted manually" % self.base_path)
shutil.rmtree(self.base_path, onerror=onerror)
os.mkdir(self.base_path)
f = open(marker_file, 'w')
......@@ -335,7 +358,8 @@ class TestFileEnvironment(object):
__tracebackhide__ = True
if not self.temp_path:
raise Exception('You cannot use assert_no_error unless you '
'instantiate TestFileEnvironment(capture_temp=True)')
'instantiate '
'TestFileEnvironment(capture_temp=True)')
names = os.listdir(self.temp_path)
if not names:
return
......@@ -348,6 +372,7 @@ class TestFileEnvironment(object):
'Temporary files left over: %s'
% ', '.join(sorted(names)))
class ProcResult(object):
"""
......@@ -387,7 +412,7 @@ class ProcResult(object):
self.files_deleted[path] = f
continue
del self.files_created[path]
if f.mtime < files_after[path].mtime:
if f != files_after[path]:
self.files_updated[path] = files_after[path]
if sys.platform == 'win32':
self.stdout = self.stdout.replace('\n\r', '\n')
......@@ -419,7 +444,9 @@ class ProcResult(object):
print(self)
else:
print('Temp files:')
print(', '.join(sorted(f.path for f in sorted(files, key=lambda x: x.path))))
print(', '.join(sorted(
f.path for f in sorted(files, key=lambda x: x.path)
)))
raise AssertionError("temp files not expected")
def wildcard_matches(self, wildcard):
......@@ -457,9 +484,9 @@ class ProcResult(object):
s.append('-- stdout: --------------------')
s.append(self.stdout)
for name, files, show_size in [
('created', self.files_created, True),
('deleted', self.files_deleted, True),
('updated', self.files_updated, True)]:
('created', self.files_created, True),
('deleted', self.files_deleted, True),
('updated', self.files_updated, True)]:
if files:
s.append('-- %s: -------------------' % name)
files = list(files.items())
......@@ -477,6 +504,7 @@ class ProcResult(object):
s.append(t)
return '\n'.join(s)
class FoundFile(object):
"""
......@@ -519,10 +547,13 @@ class FoundFile(object):
self.stat = os.stat(self.full)
self.mtime = self.stat.st_mtime
self.size = self.stat.st_size
with open(self.full, "rb") as fp:
self.hash = zlib.crc32(fp.read())
else:
self.invalid = True
self.stat = self.mtime = None
self.size = 'N/A'
self.hash = None
self._bytes = None
def bytes__get(self):
......@@ -549,6 +580,20 @@ class FoundFile(object):
self.__class__.__name__,
self.base_path, self.path)
def __eq__(self, other):
if not isinstance(other, FoundFile):
return NotImplemented
return (
self.hash == other.hash
and self.mtime == other.mtime
and self.size == other.size
)
def __ne__(self, other):
return not self == other
class FoundDir(object):
"""
......@@ -572,6 +617,16 @@ class FoundDir(object):
self.__class__.__name__,
self.base_path, self.path)
def __eq__(self, other):
if not isinstance(other, FoundDir):
return NotImplemented
return self.mtime == other.mtime
def __ne__(self, other):
return not self == other
def _popget(d, key, default=None):
"""
Pop the key if found (else return default)
......@@ -580,6 +635,7 @@ def _popget(d, key, default=None):
return d.pop(key)
return default
def _space_prefix(pref, full, sep=None, indent=None, include_sep=True):
"""
Anything shared by pref and full will be replaced with spaces
......
import sys
def string(string):
if sys.version_info >= (3,):
if isinstance(string, str):
return string
return str(string, "utf-8")
else:
if isinstance(string, unicode):
return string
return string.decode('utf-8')
[nosetests]
with-doctest = 1
doctest-extension = txt
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
[nosetests]
doctest-extension = txt
with-doctest = 1
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import sys, os
version = '1.2'
setup(name='ScriptTest',
version=version,
description="Helper to test command-line scripts",
long_description="""\
ScriptTest is a library to help you test your interactive command-line
applications.
With it you can easily run the command (in a subprocess) and see the
output (stdout, stderr) and any file modifications.
* The `source repository <http://bitbucket.org/ianb/scripttest/>`_.
""",
classifiers=[
import sys
import setuptools
import setuptools.command.test
class PyTest(setuptools.command.test.test):
def finalize_options(self):
setuptools.command.test.test.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
sys.exit(pytest.main(self.test_args))
setuptools.setup(
name='scripttest',
version="1.3",
description="Helper to test command-line scripts",
long_description=open("README.rst").read(),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Testing",
],
keywords='test unittest doctest command line scripts',
author='Ian Bicking',
author_email='ianb@colorstudy.com',
url='http://pythonpaste.org/scripttest/',
license='MIT',
packages=["scripttest"],
test_suite='nose.collector',
tests_require=['nose'],
zip_safe=True,
)
],
keywords='test unittest doctest command line scripts',
author='Ian Bicking',
author_email='ianb@colorstudy.com',
url='http://pythonpaste.org/scripttest/',
license='MIT',
py_modules=["scripttest"],
tests_require=['pytest'],
cmdclass={'test': PyTest},
zip_safe=True,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment