Ejemplo n.º 1
0
 def run(self, result=None):
     with temp_dir() as dirname:
         self.temporary_dir = dirname
         os.mkdir(os.path.join(dirname, "bin"))
         with open(os.path.join(dirname, "bin", "python"), "w"):
             pass
         super().run(result)
Ejemplo n.º 2
0
    def run(self, result=None):
        runner = self.runner = mock.MagicMock(name="subprocess.run")

        def venv_maker(args):
            if args[0].endswith("python") and args[1:3] == ["-m", "venv"]:
                environment = args[3]
                os.makedirs(os.path.join(environment, "bin"))
                with open(os.path.join(environment, "bin", "python"), "w"):
                    pass
            return mock.MagicMock(
                name="process_results",
                returncode=0,
                stdout="finished {args}",
                stderr="",
            )

        runner.side_effect = venv_maker
        with contextlib.ExitStack() as stack:
            self.temporary_dir = stack.enter_context(temp_dir())
            self.stdout = stack.enter_context(
                mock.patch(
                    "sys.stdout",
                    new=io.StringIO(),
                )
            )
            super().run(result)
Ejemplo n.º 3
0
 def test_happy_path_existing_files(self):
     runner = mock.MagicMock()
     runner.return_value.returncode = 0
     with temp_dir() as dirname:
         environment = os.path.join(dirname, "best-env")
         os.makedirs(os.path.join(environment, "bin"))
         with open(os.path.join(environment, "bin", "python"), "w"):
             pass
         with mock.patch("sys.stdout", new=io.StringIO()) as new_stdout:
             commands.add(environment, None, None, runner, {}, None)
     output = new_stdout.getvalue().split()
     assert_that(output, has_items_in_order(environment, "best-env", "jupyter"))
     assert_that(runner.call_count, equal_to(3))
Ejemplo n.º 4
0
 def test_happy_path_workon_home_default_env(self):
     runner = mock.MagicMock()
     runner.return_value.returncode = 0
     with temp_dir() as dirname:
         environment = os.path.join(dirname, "best-env")
         cwd = os.path.join(dirname, "this-doesnt-exist", "best-env")
         os_environ = dict(WORKON_HOME=dirname)
         os.makedirs(os.path.join(environment, "bin"))
         with open(os.path.join(environment, "bin", "python"), "w"):
             pass
         with mock.patch("sys.stdout", new=io.StringIO()) as new_stdout:
             commands.add(None, None, None, runner, os_environ, cwd)
     output = new_stdout.getvalue().split()
     assert_that(output, has_items_in_order(environment, "best-env", "jupyter"))
     assert_that(runner.call_count, equal_to(3))
Ejemplo n.º 5
0
 def test_no_workon_no_env(self):
     runner = mock.MagicMock()
     runner.return_value.returncode = 0
     with temp_dir() as dirname:
         environment = os.path.join(dirname, "best-env")
         cwd = os.path.join(dirname, "this-doesnt-exist", "best-env")
         os_environ = {}
         os.makedirs(os.path.join(environment, "bin"))
         with open(os.path.join(environment, "bin", "python"), "w"):
             pass
         with mock.patch("sys.stdout", new=io.StringIO()) as new_stdout:
             commands.add(None, None, None, runner, os_environ, cwd)
     lines = new_stdout.getvalue().splitlines()
     assert_that(
         lines,
         contains_exactly(
             contains_string("WORKON_HOME"),
         ),
     )