示例#1
0
    def test_shell_ok(self):
        main_entry_point(["create"])

        with TemporaryDirectory() as td:
            dir_to_create = Path(td) / "to_be_or_not_to_be"
            self.assertFalse(dir_to_create.exists())
            dir_to_create_quoted = repr(str(dir_to_create))
            bash_input = f'mkdir {dir_to_create_quoted}\n'

            # I did not find an easy way to run an interactive sub-shell during
            # testing and then to kill it. Solutions that were based on
            # signal.SIGALRM or the subprocess.run(timeout), were harming the
            # MacOS terminal that started the test
            #
            # So we provide input and delay arguments to the sub-shell. It
            # makes the sub-shell peacefully close itself.
            #
            # It is not a clean test for "shell" though. The "shell" meant to
            # be run without parameters.

            start = timer()
            with TimeLimited(10):  # safety net
                with self.assertRaises(ChildExit) as ce:
                    main_entry_point(
                        ["shell", "--input", bash_input, "--delay", "1"])
                self.assertFalse(ce.exception.code, 0)
            end = timer()

            self.assertGreater(end - start, 0.5)
            self.assertLess(end - start, 3)
            self.assertTrue(dir_to_create.exists())
示例#2
0
 def test_input_delay(self):
     start = timer()
     # run interactive shell end type "exit" after small delay
     with TimeLimited(seconds=10):  # safety net
         run_as_bash_script("exec bash",
                            input="exit\n".encode(),
                            input_delay=1,
                            timeout=10,
                            capture_output=True)
     end = timer()
     self.assertGreater(end - start, 0.9)
     self.assertLess(end - start, 5)
示例#3
0
    def test_shell_but_no_venv(self):
        # python3 -m unittest svet.main_test.TestsInsideTempProjectDir.test_shell

        with TimeLimited(10):  # safety net
            with self.assertRaises(VenvDoesNotExistExit) as cm:
                main_entry_point(["shell"])
示例#4
0
 def test_shell_exit_code_zero(self):
     main_entry_point(["create"])
     with TimeLimited(10):  # safety net
         with self.assertRaises(ChildExit) as ce:
             main_entry_point(["shell", "--input", "exit"])
         self.assertFalse(ce.exception.code, 0)
示例#5
0
 def test_shell_but_no_venv(self):
     with TimeLimited(10):  # safety net
         with self.assertRaises(VenvDoesNotExistExit) as cm:
             main_entry_point(["shell"])