dbname = 'test-db', dumps = [('/tmp/tmpma31iz1f/init.sql', 'psql')]
def db_create(dbname, dumps=None):
"""create the test DB and load the test data dumps into it
dumps is an iterable of couples (dump_file, dump_type).
context: setUpClass
"""
try:
> pg_createdb(dbname)
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:81:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dbname = 'test-db', check = True
def pg_createdb(dbname, check=True):
"""Create a db. If check is True and the db already exists, this will
raise an exception (original behavior). If check is False and
the db already exists, this will fail silently. If the db does
not exist, the db will be created.
"""
> subprocess.run(["createdb", dbname], check=check)
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:69:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
input = None, capture_output = False, timeout = None, check = True
popenargs = (['createdb', 'test-db'],), kwargs = {}
process = <subprocess.Popen object at 0x7f3ff8d9ba20>, stdout = None
stderr = None, retcode = 1
def run(*popenargs,
input=None, capture_output=False, timeout=None, check=False, **kwargs):
"""Run command with arguments and return a CompletedProcess instance.
The returned instance will have attributes args, returncode, stdout and
stderr. By default, stdout and stderr are not captured, and those attributes
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
If check is True and the exit code was non-zero, it raises a
CalledProcessError. The CalledProcessError object will have the return code
in the returncode attribute, and output & stderr attributes if those streams
were captured.
If timeout is given, and the process takes too long, a TimeoutExpired
exception will be raised.
There is an optional argument "input", allowing you to
pass bytes or a string to the subprocess's stdin. If you use this argument
you may not also use the Popen constructor's "stdin" argument, as
it will be used internally.
By default, all communication is in bytes, and therefore any "input" should
be bytes, and the stdout and stderr will be bytes. If in text mode, any
"input" should be a string, and stdout and stderr will be strings decoded
according to locale encoding, or by "encoding" if set. Text mode is
triggered by setting any of text, encoding, errors or universal_newlines.
The other arguments are the same as for the Popen constructor.
"""
if input is not None:
if 'stdin' in kwargs:
raise ValueError('stdin and input arguments may not both be used.')
kwargs['stdin'] = PIPE
if capture_output:
if ('stdout' in kwargs) or ('stderr' in kwargs):
raise ValueError('stdout and stderr arguments may not be used '
'with capture_output.')
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
with Popen(*popenargs, **kwargs) as process:
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except TimeoutExpired:
process.kill()
stdout, stderr = process.communicate()
raise TimeoutExpired(process.args, timeout, output=stdout,
stderr=stderr)
except: # Including KeyboardInterrupt, communicate handled that.
process.kill()
# We don't call process.wait() as .__exit__ does that for us.
raise
retcode = process.poll()
if check and retcode:
raise CalledProcessError(retcode, process.args,
> output=stdout, stderr=stderr)
E subprocess.CalledProcessError: Command '['createdb', 'test-db']' returned non-zero exit status 1.
/usr/lib/python3.7/subprocess.py:487: CalledProcessError
During handling of the above exception, another exception occurred:
cls = <class 'swh.core.db.tests.test_db.TestDb'>
@classmethod
def setUpClass(cls):
with tempfile.TemporaryDirectory() as td:
with open(os.path.join(td, "init.sql"), "a") as fd:
fd.write(INIT_SQL)
cls.TEST_DB_DUMP = os.path.join(td, "*.sql")
> super().setUpClass()
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/test_db.py:271:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:298: in setUpClass
super().setUpClass()
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:208: in setUpClass
cls._DB_LIST[name].__enter__()
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:140: in __enter__
db_create(dbname=self.dbname, dumps=self.dumps)
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:83: in db_create
pg_dropdb(dbname) # the db already existed
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/db_testing.py:59: in pg_dropdb
subprocess.check_call(["dropdb", dbname])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
popenargs = (['dropdb', 'test-db'],), kwargs = {}, retcode = 1
cmd = ['dropdb', 'test-db']
def check_call(*popenargs, **kwargs):
"""Run command with arguments. Wait for command to complete. If
the exit code was zero then return, otherwise raise
CalledProcessError. The CalledProcessError object will have the
return code in the returncode attribute.
The arguments are the same as for the call function. Example:
check_call(["ls", "-l"])
"""
retcode = call(*popenargs, **kwargs)
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
> raise CalledProcessError(retcode, cmd)
E subprocess.CalledProcessError: Command '['dropdb', 'test-db']' returned non-zero exit status 1.
/usr/lib/python3.7/subprocess.py:347: CalledProcessError
TEST RESULT
TEST RESULT
- Run At
- Nov 23 2020, 1:51 PM