Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
TestCase Class Reference

Public Member Functions

None __init__ (self, str test_filename, Options options)
 
str name (self)
 
None launch (self)
 
bool analyze (self)
 
bool run (self)
 
None __init__ (self, str test_filename, Options options)
 
str name (self)
 
None launch (self)
 
bool analyze (self)
 
bool run (self)
 

Protected Member Functions

None _log (self, *args, **kwargs)
 
None _vlog (self, *args, **kwargs)
 
typing.Dict[str, str_test_environment (self)
 
None _launch_test (self)
 
None _join_test (self)
 
None _check_output_exact (self, str out_name, bytes expected, str exact_name)
 
None _check_output_glob (self, str out_name, bytes expected)
 
None _check_output (self, str out_name)
 
None _check_stderr (self)
 
None _check_stdout (self)
 
None _check_exit (self)
 
None _analyze_results (self)
 
None _log (self, *args, **kwargs)
 
None _vlog (self, *args, **kwargs)
 
typing.Dict[str, str_test_environment (self)
 
None _launch_test (self)
 
None _join_test (self)
 
None _check_output_exact (self, str out_name, bytes expected, str exact_name)
 
None _check_output_glob (self, str out_name, bytes expected)
 
None _check_output (self, str out_name)
 
None _check_stderr (self)
 
None _check_stdout (self)
 
None _check_exit (self)
 
None _analyze_results (self)
 

Protected Attributes

 _opts = options
 
 _test_file = test_filename
 
 _test_name
 
dict _success = {}
 
dict _message = {}
 
 _test_stdin = None
 
 _scratch_dir = os.path.abspath(os.path.join(self._opts.scratch_dir, self._test_name))
 
 _test_process
 
dict _output = {}
 
 _exit_code = self._test_process.returncode
 
 _succeeded = all(self._success.values())
 

Detailed Description

Logic and state related to running a single test case.

1. Initialize the test case.
2. Launch the test case with :TestCase.launch():.
   This will start the test execution in a subprocess, but
   not wait for completion. So you could launch multiple test
   cases in parallel. This will now print any test output.
3. Analyze the results with :TestCase.analyze():. This will
   join the test subprocess, check the results against the
   expectations, and print the results to stdout.

:TestCase.run(): is also provided which combines the launch & analyze
steps for single-threaded use-cases.

All other methods, prefixed with _, are private helper functions.

Constructor & Destructor Documentation

◆ __init__() [1/2]

None __init__ ( self,
str test_filename,
Options options )
Initialize the :TestCase: for the test located in :test_filename:
with the given :options:.

◆ __init__() [2/2]

None __init__ ( self,
str test_filename,
Options options )
Initialize the :TestCase: for the test located in :test_filename:
with the given :options:.

Member Function Documentation

◆ _analyze_results() [1/2]

None _analyze_results ( self)
protected
After all tests have been checked, collect all the successes
and messages, and print the results to stdout.

◆ _analyze_results() [2/2]

None _analyze_results ( self)
protected
After all tests have been checked, collect all the successes
and messages, and print the results to stdout.

◆ _check_exit() [1/2]

None _check_exit ( self)
protected
Checks the exit code against expectations. If a .exit file
exists, we expect that the exit code matches the contents.
Otherwise we expect the exit code to be zero.

If :Options.preserve: is set we save the exit code to the
scratch directory under the filename "exit".

◆ _check_exit() [2/2]

None _check_exit ( self)
protected
Checks the exit code against expectations. If a .exit file
exists, we expect that the exit code matches the contents.
Otherwise we expect the exit code to be zero.

If :Options.preserve: is set we save the exit code to the
scratch directory under the filename "exit".

◆ _check_output() [1/2]

None _check_output ( self,
str out_name )
protected
Checks the output named :out_name: for a match against the expectation.
We check for a .exact, .glob, and a .ignore file. If none are found we
expect that the output should be empty.

If :Options.preserve: was set then we save the scratch directory and
save the stderr, stdout, and exit code to the scratch directory for
debugging.

◆ _check_output() [2/2]

None _check_output ( self,
str out_name )
protected
Checks the output named :out_name: for a match against the expectation.
We check for a .exact, .glob, and a .ignore file. If none are found we
expect that the output should be empty.

If :Options.preserve: was set then we save the scratch directory and
save the stderr, stdout, and exit code to the scratch directory for
debugging.

◆ _check_output_exact() [1/2]

None _check_output_exact ( self,
str out_name,
bytes expected,
str exact_name )
protected
Check the output named :out_name: for an exact match against the :expected: content.
Saves the success and message.

◆ _check_output_exact() [2/2]

None _check_output_exact ( self,
str out_name,
bytes expected,
str exact_name )
protected
Check the output named :out_name: for an exact match against the :expected: content.
Saves the success and message.

◆ _check_output_glob() [1/2]

None _check_output_glob ( self,
str out_name,
bytes expected )
protected
Check the output named :out_name: for a glob match against the :expected: glob.
Saves the success and message.

◆ _check_output_glob() [2/2]

None _check_output_glob ( self,
str out_name,
bytes expected )
protected
Check the output named :out_name: for a glob match against the :expected: glob.
Saves the success and message.

◆ _check_stderr() [1/2]

None _check_stderr ( self)
protected
Checks the stderr output against the expectation.

◆ _check_stderr() [2/2]

None _check_stderr ( self)
protected
Checks the stderr output against the expectation.

◆ _check_stdout() [1/2]

None _check_stdout ( self)
protected
Checks the stdout output against the expectation.

◆ _check_stdout() [2/2]

None _check_stdout ( self)
protected
Checks the stdout output against the expectation.

◆ _join_test() [1/2]

None _join_test ( self)
protected
Join the test process and save stderr, stdout, and the exit code.

◆ _join_test() [2/2]

None _join_test ( self)
protected
Join the test process and save stderr, stdout, and the exit code.

◆ _launch_test() [1/2]

None _launch_test ( self)
protected
Launch the test subprocess, but do not join it.

◆ _launch_test() [2/2]

None _launch_test ( self)
protected
Launch the test subprocess, but do not join it.

◆ _log() [1/2]

None _log ( self,
* args,
** kwargs )
protected
Logs test output.

◆ _log() [2/2]

None _log ( self,
* args,
** kwargs )
protected
Logs test output.

◆ _test_environment() [1/2]

typing.Dict[str, str] _test_environment ( self)
protected
Returns the environment to be used for the
test subprocess.

◆ _test_environment() [2/2]

typing.Dict[str, str] _test_environment ( self)
protected
Returns the environment to be used for the
test subprocess.

◆ _vlog() [1/2]

None _vlog ( self,
* args,
** kwargs )
protected
Logs verbose test output.

◆ _vlog() [2/2]

None _vlog ( self,
* args,
** kwargs )
protected
Logs verbose test output.

◆ analyze() [1/2]

bool analyze ( self)
Must be called after :TestCase.launch():. Joins the test subprocess and
checks the results against expectations. Finally prints the results to
stdout and returns the success.

◆ analyze() [2/2]

bool analyze ( self)
Must be called after :TestCase.launch():. Joins the test subprocess and
checks the results against expectations. Finally prints the results to
stdout and returns the success.

◆ launch() [1/2]

None launch ( self)
Launch the test case as a subprocess, but do not block on completion.
This allows users to run multiple tests in parallel. Results aren't yet
printed out.

◆ launch() [2/2]

None launch ( self)
Launch the test case as a subprocess, but do not block on completion.
This allows users to run multiple tests in parallel. Results aren't yet
printed out.

◆ name() [1/2]

str name ( self)
Returns the unique name for the test.

◆ name() [2/2]

str name ( self)
Returns the unique name for the test.

◆ run() [1/2]

bool run ( self)
Shorthand for combining both :TestCase.launch(): and :TestCase.analyze():.

◆ run() [2/2]

bool run ( self)
Shorthand for combining both :TestCase.launch(): and :TestCase.analyze():.

Field Documentation

◆ _exit_code

_exit_code = self._test_process.returncode
protected

◆ _message

dict _message = {}
protected

◆ _opts

_opts = options
protected

◆ _output

dict _output = {}
protected

◆ _scratch_dir

_scratch_dir = os.path.abspath(os.path.join(self._opts.scratch_dir, self._test_name))
protected

◆ _succeeded

_succeeded = all(self._success.values())
protected

◆ _success

dict _success = {}
protected

◆ _test_file

_test_file = test_filename
protected

◆ _test_name

_test_name
protected
Initial value:
= os.path.normpath(
os.path.relpath(test_filename, start=self._opts.test_dir)
)

◆ _test_process

_test_process
protected
Initial value:
= subprocess.Popen(
args=args,
stdin=stdin,
cwd=cwd,
env=env,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE
)

◆ _test_stdin

_test_stdin = None
protected

The documentation for this class was generated from the following files: