예제 #1
0
    def __init__(self, env_name: str, tmp_dir: Any = None) -> None:
        """
        Creates a new virtual environment in a temporary folder.

        :param env_name: Name of the virtual environment
        :param tmp_dir: Directory where the temporary folder should be created
        """
        Preconditions.check_argument(
            len(env_name) > 0,
            "Cannot create an virtual environment without a name!",
        )
        self._env_name = env_name
        self._packages: List[str] = []

        self._env_dir = tempfile.mkdtemp(suffix=env_name, dir=tmp_dir)
        virtualenv.create_environment(self._env_dir)
예제 #2
0
 def test_check_argument_false_msg(self):
     m = "message"
     with self.assertRaises(IllegalArgumentException) as context:
         Preconditions.check_argument(False, m)
     self.assertTrue(m in str(context.exception))
예제 #3
0
 def test_check_argument_true_msg(self):
     try:
         Preconditions.check_argument(True, "message")
     except IllegalArgumentException:  # pragma: no cover
         self.fail("check_argument() raised IllegalArgumentException "
                   "unexpectedly!")  # pragma: no cover
예제 #4
0
 def test_check_argument_false_no_msg(self):
     with self.assertRaises(IllegalArgumentException) as context:
         Preconditions.check_argument(False)
     self.assertTrue(isinstance(context.exception,
                                IllegalArgumentException))
예제 #5
0
 def test_check_state_false_no_msg(self):
     with self.assertRaises(IllegalStateException) as context:
         Preconditions.check_state(False)
     self.assertTrue(isinstance(context.exception, IllegalStateException))
예제 #6
0
 def test_check_state_false_msg(self):
     m = "message"
     with self.assertRaises(IllegalStateException) as context:
         Preconditions.check_state(False, m)
     self.assertTrue(m in str(context.exception))
예제 #7
0
 def test_check_state_true_msg(self):
     try:
         Preconditions.check_state(True, "message")
     except IllegalStateException:  # pragma: no cover
         self.fail("check_state() raised IllegalStateException "
                   "unexpectedly!")  # pragma: no cover
예제 #8
0
 def test_check_not_none_with_none_msg(self):
     i = None
     m = "message"
     with self.assertRaises(NoneValueException) as context:
         Preconditions.check_not_none(i, m)
     self.assertTrue(m in str(context.exception))
예제 #9
0
 def test_check_not_none_with_none_no_msg(self):
     i = None
     with self.assertRaises(NoneValueException) as context:
         Preconditions.check_not_none(i)
     self.assertTrue(isinstance(context.exception, NoneValueException))
예제 #10
0
 def test_check_not_none_without_none_msg(self):
     i = 42
     r = Preconditions.check_not_none(i, "message")
     self.assertEqual(i, r)
예제 #11
0
 def test_check_not_none_without_none_no_msg(self):
     i = 42
     self.assertEqual(i, Preconditions.check_not_none(i))