Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _run(self, *cmdargs):
cmdargs = [str(x) for x in cmdargs]
p1 = self.tmpdir.join("stdout")
p2 = self.tmpdir.join("stderr")
print_("running:", ' '.join(cmdargs))
print_(" in:", str(py.path.local()))
f1 = codecs.open(str(p1), "w", encoding="utf8")
f2 = codecs.open(str(p2), "w", encoding="utf8")
try:
now = time.time()
popen = self.popen(cmdargs, stdout=f1, stderr=f2,
close_fds=(sys.platform != "win32"))
ret = popen.wait()
finally:
f1.close()
f2.close()
f1 = codecs.open(str(p1), "r", encoding="utf8")
f2 = codecs.open(str(p2), "r", encoding="utf8")
try:
out = f1.read().splitlines()
err = f2.read().splitlines()
finally:
def test_repr_tracebackentry_short(self):
mod = self.importasmod("""
def func1():
raise ValueError("hello")
def entry():
func1()
""")
excinfo = py.test.raises(ValueError, mod.entry)
p = FormattedExcinfo(style="short")
reprtb = p.repr_traceback_entry(excinfo.traceback[-2])
lines = reprtb.lines
basename = py.path.local(mod.__file__).basename
assert lines[0] == ' File "%s", line 5, in entry' % basename
assert lines[1] == ' func1()'
# test last entry
p = FormattedExcinfo(style="short")
reprtb = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
lines = reprtb.lines
assert lines[0] == ' File "%s", line 3, in func1' % basename
assert lines[1] == ' raise ValueError("hello")'
assert lines[2] == 'E ValueError: hello'
import nose
import ConfigParser
import lxml.cssselect
import lxml.html.soupparser
import mechanize
import py
import re
import subprocess
import sys
import tempfile
import unittest2 as unittest
CONFIG_FILE = py.path.local(__file__).dirpath().dirpath().dirpath().join('dex.conf').strpath
CONFIG = ConfigParser.ConfigParser()
CONFIG.read(CONFIG_FILE)
LOCK_FILE = py.path.local(CONFIG.get('functest', 'functestLockFile'))
URL_BASE = CONFIG.get('functest', 'baseUrl').strip(' \'"')
def parseDsn(dsn):
dsnPattern = re.compile("(^\w+)://(\w+)(:(\w+))?@(\w+)(:(\d+))?/(\w+)$");
match = dsnPattern.match(dsn)
if match is None:
return None
groups = match.groups()
assert groups[0] == 'mysql' # we can only handle the mysql protocol
assert groups[6] is None # we cannot handle port numbers
return { 'user': groups[1], 'password': groups[3], 'host': groups[4], 'database': groups[7] }
# Takes a dictionary obtained with parseDsn
def getMysqlArgs(dict):
result = ['-u', dict['user'], '-h', dict['host']]
if dict['password'] is not None:
def test_tikz_config_options(monkeypatch, tmpdir, document):
mock_call = Mock()
mock_move = Mock()
monkeypatch.setattr('subprocess.call', mock_call)
monkeypatch.setattr('os.remove', Mock)
monkeypatch.setattr('shutil.move', mock_move)
with py.path.local(os.path.dirname(__file__)).as_cwd():
doc = document(compiler='xelatex', converter='mockconv', template='tikztemplate')
tikz_tmpdir = doc.userdata['tikzpicture']['tmp_dir']
with tmpdir.as_cwd():
renderer = Renderer()
renderer.render(doc)
pics = doc.getElementsByTagName('tikzpicture')
assert pics
tex_path = os.path.join(tikz_tmpdir, pics[0].id + '.tex')
assert os.path.isfile(tex_path)
with open(tex_path, 'r') as f:
assert 'usetikzlibrary' in f.read()
assert 'xelatex' in mock_call.call_args_list[0][0][0]
assert 'mockconv' in mock_call.call_args_list[1][0][0]
def generate_script(entry, packages):
data = compress_packages(packages)
tmpl = py.path.local(__file__).dirpath().join('standalonetemplate.py')
exe = tmpl.read()
exe = exe.replace('@SOURCES@', data)
exe = exe.replace('@ENTRY@', entry)
return exe
def getbasetemp(self):
""" return base temporary directory. """
try:
return self._basetemp
except AttributeError:
basetemp = self.config.option.basetemp
if basetemp:
basetemp = py.path.local(basetemp)
if basetemp.check():
basetemp.remove()
basetemp.mkdir()
else:
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
self._basetemp = t = basetemp
self.trace("new basetemp", t)
return t
def _makepath(self, path):
if not self.abspath:
try:
np = py.path.local().bestrelpath(path)
except OSError:
return path
if len(np) < len(str(path)):
path = np
return path
"""
Search the list of arguments for a valid ini-file for pytest,
and return a tuple of (rootdir, inifile, cfg-dict).
note: warnfunc is an optional function used to warn
about ini-files that use deprecated features.
This parameter should be removed when pytest
adopts standard deprecation warnings (#1804).
"""
from _pytest.deprecated import SETUP_CFG_PYTEST
inibasenames = ["pytest.ini", "tox.ini", "setup.cfg"]
args = [x for x in args if not str(x).startswith("-")]
if not args:
args = [py.path.local()]
for arg in args:
arg = py.path.local(arg)
for base in arg.parts(reverse=True):
for inibasename in inibasenames:
p = base.join(inibasename)
if exists(p):
iniconfig = py.iniconfig.IniConfig(p)
if 'pytest' in iniconfig.sections:
if inibasename == 'setup.cfg' and warnfunc:
warnfunc('C1', SETUP_CFG_PYTEST)
return base, p, iniconfig['pytest']
if inibasename == 'setup.cfg' and 'tool:pytest' in iniconfig.sections:
return base, p, iniconfig['tool:pytest']
elif inibasename == "pytest.ini":
# allowed to be empty
return base, p, {}
return None, None, None
def start(self, args, argv):
filtered_args = [x for x in argv if x not in ("--start", "--init")]
devpi_server = sys.argv[0]
if devpi_server is None:
self.fatal("cannot find devpi-server binary, no auto-start")
devpi_server = os.path.abspath(devpi_server)
if devpi_server.endswith(".py") and sys.platform == "win32":
devpi_server = str(py.path.local.sysfind("devpi-server"))
if not (py.path.local(devpi_server).exists()
or py.path.local(devpi_server + '.exe').exists()):
self.fatal("not existing devpi-server: %r" % devpi_server)
url = "http://%s:%s" % (args.host, args.port)
if self._waitup(url, count=1):
self.fatal("a server is already running at %s" % url)
def prepare_devpiserver(cwd):
self.line("starting background devpi-server at %s" % url)
argv = [devpi_server, ] + filtered_args
return (lambda: self._waitup(url), argv)
self.xproc.ensure("devpi-server", prepare_devpiserver)
info = self.xproc.getinfo("devpi-server")
self.pid = info.pid
self.logfile = info.logpath
self.line("logfile is at %s" % self.logfile)