def test_run_list_expressions(self): with TestIO() as io: with self.assertRaises(SystemExit) as call: stubbox_main(['dev', 'special', '--list-expressions']) self.assertEqual(call.exception.args, (0, )) self.assertIn('stub_package.name == "checkbox"', io.stdout.splitlines())
def test_version(self): with TestIO(combined=True) as io: with self.assertRaises(SystemExit) as call: stubbox_main(['--version']) self.assertEqual(call.exception.args, (0,)) self.assertEqual(io.combined, "{}\n".format( ToolBase.format_version_tuple(version)))
def test_run_dot(self): with TestIO() as io: with self.assertRaises(SystemExit) as call: stubbox_main(['dev', 'special', '--dot']) self.assertEqual(call.exception.args, (0, )) self.assertIn('\t"com.canonical.plainbox::stub/true" [];', io.stdout.splitlines()) # Do basic graph checks self._check_digraph_sanity(io)
def test_run_list_jobs(self): with TestIO() as io: with self.assertRaises(SystemExit) as call: stubbox_main(['dev', 'special', '--list-jobs']) self.assertEqual(call.exception.args, (0, )) self.assertIn("com.canonical.plainbox::stub/false", io.stdout.splitlines()) self.assertIn("com.canonical.plainbox::stub/true", io.stdout.splitlines())
def test_run_list_jobs_with_filtering(self): with TestIO() as io: with self.assertRaises(SystemExit) as call: stubbox_main(['dev', 'special', ('--include-pattern=' '2013.com.canonical.plainbox::stub/false'), '--list-jobs']) self.assertEqual(call.exception.args, (0,)) self.assertIn( "2013.com.canonical.plainbox::stub/false", io.stdout.splitlines()) self.assertNotIn( "2013.com.canonical.plainbox::stub/true", io.stdout.splitlines())
def test_run_dot_with_resources(self): with TestIO() as io: with self.assertRaises(SystemExit) as call: stubbox_main(['dev', 'special', '--dot', '--dot-resources']) self.assertEqual(call.exception.args, (0, )) self.assertIn('\t"com.canonical.plainbox::stub/true" [];', io.stdout.splitlines()) self.assertIn( ('\t"com.canonical.plainbox::stub/requirement/good" -> ' '"com.canonical.plainbox::stub_package" [style=dashed, label' '="stub_package.name == \'checkbox\'"];'), io.stdout.splitlines()) # Do basic graph checks self._check_digraph_sanity(io)
def execute_job(job_id): """ Execute the specified job. The job is invoked using a high-level interface from box so the test will actually execute the same way as the UI would execute it. It will create/tear-down appropriate session objects as well. Returns (result, return_code) where result is the deserialized JSON saved at the end of the job. """ # Create a scratch directory so that we can save results there. The # shared directory is also used for running tests as some test jobs # leave junk around the current directory. with TemporaryDirectory() as scratch_dir: # Save results to results.json in the scratch directory pathname = os.path.join(scratch_dir, 'results.json') # Redirect all standard IO so that the test is silent. # Run the script, having relocated to the scratch directory with TestIO() as io, TestCwd(scratch_dir): try: stubbox_main([ 'run', '-i', job_id, '--output-format=2013.com.canonical.plainbox::json', '-o', pathname]) except SystemExit as exc: # Capture SystemExit that is always raised by stubbox_main() so that we # can observe the return code as well. job_return_code = exc.args[0] else: job_return_code = None # Load the actual results and keep them in memory with open(pathname, encoding='UTF-8') as stream: job_result = json.load(stream) job_outcome = job_result['result_map'][job_id]['outcome'] job_execution_duration = job_result['result_map'][job_id] \ ['execution_duration'] # [ At this time TestIO and TemporaryDirectory are gone ] return (job_id, job_outcome, job_execution_duration, job_return_code, io.stdout, io.stderr)