Skip to content
Snippets Groups Projects
Commit bc77478b authored by Adriaan de Groot's avatar Adriaan de Groot
Browse files

[calamares] Expand test-mocks for Python

- the rawfs module uses more parts of the subprocess Python module
  and so needs more things mocked for testing.
parent 0d2763f6
No related branches found
No related tags found
No related merge requests found
...@@ -389,10 +389,9 @@ createApplication( int& argc, char* argv[] ) ...@@ -389,10 +389,9 @@ createApplication( int& argc, char* argv[] )
} }
#ifdef WITH_PYTHON #ifdef WITH_PYTHON
static const char pythonPreScript[] = R"( static const char pythonPreScript[] = R"%(
# This is Python code executed by Python modules *before* the # This is Python code executed by Python modules *before* the
# script file (e.g. main.py) is executed. Beware " before ) # script file (e.g. main.py) is executed.
# because it's a C++ raw-string.
# #
# Calls to suprocess methods that execute something are # Calls to suprocess methods that execute something are
# suppressed and logged -- scripts should really be using libcalamares # suppressed and logged -- scripts should really be using libcalamares
...@@ -401,20 +400,32 @@ _calamares_subprocess = __import__("subprocess", globals(), locals(), [], 0) ...@@ -401,20 +400,32 @@ _calamares_subprocess = __import__("subprocess", globals(), locals(), [], 0)
import sys import sys
import libcalamares import libcalamares
class fake_subprocess(object): class fake_subprocess(object):
PIPE = object()
STDOUT = object()
STDERR = object()
class CompletedProcess(object):
returncode = 0
stdout = ""
stderr = ""
@staticmethod @staticmethod
def call(*args, **kwargs): def call(*args, **kwargs):
libcalamares.utils.debug("subprocess.call(%r,%r) X run normally" % (args, kwargs)) libcalamares.utils.debug("subprocess.call(%r,%r) X ignored" % (args, kwargs))
return 0 return 0
@staticmethod @staticmethod
def check_call(*args, **kwargs): def check_call(*args, **kwargs):
libcalamares.utils.debug("subprocess.check_call(%r,%r) X subverted to call" % (args, kwargs)) libcalamares.utils.debug("subprocess.check_call(%r,%r) X ignored" % (args, kwargs))
return 0 return 0
# This is a 3.5-and-later method, is supposed to return a CompletedProcess
@staticmethod
def run(*args, **kwargs):
libcalamares.utils.debug("subprocess.run(%r,%r) X ignored" % (args, kwargs))
return fake_subprocess.CompletedProcess()
for attr in ("CalledProcessError",): for attr in ("CalledProcessError",):
setattr(fake_subprocess,attr,getattr(_calamares_subprocess,attr)) setattr(fake_subprocess,attr,getattr(_calamares_subprocess,attr))
sys.modules["subprocess"] = fake_subprocess sys.modules["subprocess"] = fake_subprocess
libcalamares.utils.debug('pre-script for testing purposes injected') libcalamares.utils.debug('pre-script for testing purposes injected')
)"; )%";
#endif #endif
int int
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment