示例#1
0
 def test_call_lor_ls_emits_list_of_classes_to_stdout_and_zero_exit(self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = ["ls", "lor.tasks"]
             stdout, stderr, exit_code = run_cli(args)
             self.assertEqual(exit_code, 0)
示例#2
0
 def test_call_lor_dot_with_invalid_task_class_returns_nonzero_exit(self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = ["dot", "--module", "some.class.that.doesnt", "Exist"]
             stdout, stderr, exit_code = run_cli(args)
             self.assertNotEqual(exit_code, 0)
示例#3
0
 def test_call_lor_dot_with_help_emits_usage_to_stdout_and_zero_exit(self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = ["dot", "--help"]
             stdout, stderr, exit_code = run_cli(args)
             self.assertEqual(exit_code, 0)
             self.assertTrue("usage" in stdout)
示例#4
0
 def test_call_lor_dot_with_nothing_results_in_nonzero_exit(self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = ["dot"]
             stdout, stderr, exit_code = run_cli(args)
             self.assertNotEqual(exit_code, 0)
             self.assertTrue(len(stderr) > 0)
示例#5
0
 def test_call_lor_properties_emits_varname_varval_space_separated_and_zero_exit(
         self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = ["properties"]
             stdout, stderr, exit_code = run_cli(args)
             self.assertEqual(exit_code, 0)
示例#6
0
    def test_try_locate_returns_env_cwd_if_env_cwd_is_a_workspace(self):
        cwd = os.path.join(tempfile.mkdtemp(), "wd")
        workspace_generator.create(cwd)

        with TemporaryEnv():
            os.chdir(cwd)
            ws_path = workspace.try_locate()
            self.assertEqual(os.path.realpath(cwd), os.path.realpath(ws_path))
示例#7
0
 def test_call_lor_explain_with_nothing_emits_help_to_stderr_and_nonzero_exit(
         self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = ["explain"]
             stdout, stderr, exit_code = run_cli(args)
             self.assertTrue(len(stderr) > 0)
             self.assertNotEqual(exit_code, 0)
示例#8
0
    def test_try_locate_returns_LOR_HOME_if_it_is_set_in_env(self):
        cwd = os.path.join(tempfile.mkdtemp(), "wd")
        workspace_generator.create(cwd)

        with TemporaryEnv():
            os.environ[lor._constants.WORKSPACE_ENV_VARNAME] = cwd

            ws_path = workspace.try_locate()
            self.assertEqual(os.path.realpath(cwd), os.path.realpath(ws_path))
示例#9
0
 def test_call_lor_dot_with_valid_task_class_emits_text_to_stdout_and_zero_exit(
         self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = [
                 "dot", "--module", "lor.tasks.general", "AlwaysRunsTask"
             ]
             stdout, stderr, exit_code = run_cli(args)
             self.assertEqual(exit_code, 0)
示例#10
0
 def test_call_lor_run_with_valid_task_classname_results_in_zero_exit(self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = [
                 "run", "--module", "lor.tasks.general", "AlwaysRunsTask",
                 "--local-scheduler"
             ]
             stdout, stderr, exit_code = run_cli(args)
             self.assertEqual(exit_code, 0)
示例#11
0
    def test_destination_root_default_raises_AssertionError_if_not_in_a_workspace(self):
        non_subclassed_generator = Generator()
        empty_dir = tempfile.mkdtemp()

        with TemporaryEnv():
            workspace._set_path(None)
            os.chdir(empty_dir)

            with self.assertRaises(AssertionError):
                non_subclassed_generator.destination_root()
示例#12
0
 def test_call_lor_explain_with_invalid_classname_emits_error_to_stderr_and_nonzero_exit(
         self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = [
                 "explain", "--module", "some.class.that.doesnt", "Exist"
             ]
             stdout, stderr, exit_code = run_cli(args)
             self.assertNotEqual(exit_code, 0)
             self.assertTrue(len(stderr) > 0)
示例#13
0
 def test_call_lor_run_with_invalid_task_classname_results_in_nonzero_exit(
         self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = [
                 "run", "--module", "some.invalid.module",
                 "SomeInvalidClass"
             ]
             stdout, stderr, exit_code = run_cli(args)
             self.assertNotEqual(exit_code, 0)
示例#14
0
 def test_call_lor_explain_with_valid_classname_emits_explanation_to_stdout_and_zero_exit(
         self):
     with TemporaryWorkspace() as ws:
         with TemporaryEnv():
             os.chdir(ws)
             args = [
                 "explain", "--module", "lor.tasks.general",
                 "AlwaysRunsTask"
             ]
             stdout, stderr, exit_code = run_cli(args)
             self.assertEqual(exit_code, 0)
             self.assertTrue(len(stdout) > 0)
示例#15
0
def run_cli(args):
    with TemporaryEnv():
        # CI might be running from a non-standard dir, so need to setup the python path correctly
        # before launching off a subprocess
        os.environ["PYTHONPATH"] = os.path.normpath(
            os.path.join(os.path.dirname(__file__), "../.."))
        cli_command = lor._paths.lor_path("lor")
        all_args = ["python3", cli_command] + args

        exit_code, stdout_builder, stderr_builder = lor.util.subprocess.call_with_output_reducers(
            all_args,
            stdout_initial_state=io.StringIO(),
            stdout_reducer=__append_to_builder,
            stderr_initial_state=io.StringIO(),
            stderr_reducer=__append_to_builder)

        stdout = stdout_builder.getvalue()
        stdout_builder.close()
        stderr = stderr_builder.getvalue()
        stderr_builder.close()

        return stdout, stderr, exit_code