def test_which_not_dir(self): tmp_dir = temp_folder() dev_dir = os.path.join(tmp_dir, "Dev") dev_git_dir = os.path.join(dev_dir, "Git") mkdir(dev_git_dir) with tools.environment_append({'PATH': dev_dir}): self.assertEqual(dev_dir, tools.get_env("PATH")) self.assertIsNone(tools.which('git'))
def get_env_unit_test(self): """ Unit tests tools.get_env """ # Test default self.assertIsNone( tools.get_env("NOT_DEFINED", environment={}), None ) # Test defined default self.assertEqual( tools.get_env("NOT_DEFINED_KEY", default="random_default", environment={}), "random_default" ) # Test return defined string self.assertEqual( tools.get_env("FROM_STR", default="", environment={"FROM_STR": "test_string_value"}), "test_string_value" ) # Test boolean conversion self.assertEqual( tools.get_env("BOOL_FROM_STR", default=False, environment={"BOOL_FROM_STR": "1"}), True ) self.assertEqual( tools.get_env("BOOL_FROM_STR", default=True, environment={"BOOL_FROM_STR": "0"}), False ) self.assertEqual( tools.get_env("BOOL_FROM_STR", default=False, environment={"BOOL_FROM_STR": "True"}), True ) self.assertEqual( tools.get_env("BOOL_FROM_STR", default=True, environment={"BOOL_FROM_STR": ""}), False ) # Test int conversion self.assertEqual( tools.get_env("TO_INT", default=2, environment={"TO_INT": "1"}), 1 ) # Test float conversion self.assertEqual( tools.get_env("TO_FLOAT", default=2.0, environment={"TO_FLOAT": "1"}), 1.0 ), # Test list conversion self.assertEqual( tools.get_env("TO_LIST", default=[], environment={"TO_LIST": "1,2,3"}), ["1", "2", "3"] ) self.assertEqual( tools.get_env("TO_LIST_NOT_TRIMMED", default=[], environment={"TO_LIST_NOT_TRIMMED": " 1 , 2 , 3 "}), ["1", "2", "3"] )