Coverage for tests/test_utils/test_cases.py : 56%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# coding: utf-8
PyLucid ~~~~~~~
:copyleft: 2015-2018 by the PyLucid team, see AUTHORS for more details. :created: 2015 by JensDiemer.de :license: GNU GPL v3 or above, see LICENSE for more details. """
# https://github.com/jedie/django-tools
# PyLucid
""" Return (status, output) of executing cmd in a shell.
similar to subprocess.getstatusoutput but pass though kwargs """
# TODO: Use pylucid.pylucid_boot.VerboseSubprocess !
kwargs.update({ "shell": True, "universal_newlines": True, "stderr": subprocess.STDOUT, }) if "cwd" in kwargs: cwd = kwargs["cwd"] self.assertTrue(os.path.isdir(cwd), "cwd %r doesn't exists!" % cwd) if debug: print("DEBUG: cwd %r, ok" % cwd)
# Assume that DJANGO_SETTINGS_MODULE not in environment # e.g: # manage.py use os.environ.setdefault("DJANGO_SETTINGS_MODULE",...) # so it will ignore the own module path! env=dict(os.environ) if "DJANGO_SETTINGS_MODULE" in env: del(env["DJANGO_SETTINGS_MODULE"]) kwargs["env"] = env
cmd=" ".join(cmd) # FIXME: Why?!? try: output = subprocess.check_output(cmd, **kwargs) status = 0 except subprocess.CalledProcessError as ex: output = ex.output status = ex.returncode
if output[-1:] == '\n': output = output[:-1]
if status != 0 or debug: msg = ( "subprocess exist status == %(status)r\n" "Call %(cmd)r with:\n" "%(kwargs)s\n" "subprocess output:\n" "------------------------------------------------------------\n" "%(output)s\n" "------------------------------------------------------------\n" ) % { "status": status, "cmd": cmd, "kwargs": pprint.pformat(kwargs), "output": output } if status != 0: raise AssertionError(msg) else: print(msg)
return output
# def call_manage_py(self, cmd, **kwargs): # """ # call manage.py from pylucid_installer.page_instance_template.example_project # """ # cmd = [sys.executable, "manage.py"] + list(cmd) # kwargs.update({ # "cwd": os.path.abspath(os.path.join(os.path.dirname(example_project.__file__), "..")), # #"debug": True, # }) # return self.subprocess_getstatusoutput(cmd, **kwargs)
""" -Create a page instance with the pylucid_installer cli -run the test in the created page instance """
# We can't use the created temp path directly, # because the installer will only use a not existing directory
dest = self.instance_root, name = self.project_name, remove = False, exist_ok = False, )
"Create instance with name '%s' at: %s..." % ( self.project_name, self.instance_root ), output )
except Exception: print(output) raise
except Exception: print(manage_content) raise
# Needed until https://github.com/divio/django-cms/issues/5079 is fixed:
""" Call manage.py from created page instance in temp dir. """
# pylucid_page_instance/manage.py use os.environ.setdefault # We must remove "DJANGO_SETTINGS_MODULE" from environ!
"cwd": str(self.manage_file_path.parent), "env": env, }) except subprocess.CalledProcessError as err: print(err.output) self.fail(err)
# self.subprocess_getstatusoutput(["cat %s" % os.path.join(self.project_path, "settings.py")], **kwargs) # self.subprocess_getstatusoutput(["cat %s" % os.path.join(self.temp_path, "manage.py")], **kwargs) # self.subprocess_getstatusoutput(['python -c "import sys,pprint;pprint.pprint(sys.path)"'], **kwargs) |