def test_set_env_ok_if_not_exists(): if TEMP_NAME in os.environ: del os.environ[TEMP_NAME] with env.set_env(TEMP_NAME, 'anything'): assert os.environ[TEMP_NAME] == 'anything' assert TEMP_NAME not in os.environ
def test_set_env_ok_if_exists(): ev = os.environ[TEMP_NAME] = 'junk_name' try: with env.set_env(TEMP_NAME, 'not_junk'): assert os.environ[TEMP_NAME] == 'not_junk' assert os.environ[TEMP_NAME] == ev finally: del os.environ[TEMP_NAME]
def test_PYTHONPATH_not_present_in_testing_env_if_set(): with env.set_env('PYTHONPATH', 'fred'): with mock.patch.object(venv.Workspace, 'run') as run: venv.TmpVirtualEnv() call = run.mock_calls[0] assert 'PYTHONPATH' not in call[2]['env'] venv.TmpVirtualEnv({'PYTHONPATH': 'john'}) call = run.mock_calls[1] assert 'PYTHONPATH' not in call[2]['env']
def test_subprocess_set_env_ok_if_not_exists(): if TEMP_NAME in os.environ: del os.environ[TEMP_NAME] with env.set_env(TEMP_NAME, 'anything'): out = cmdline.launch('env')[0] for o in out.split('\n'): if o.startswith(TEMP_NAME): assert o == '%s=anything' % TEMP_NAME break else: assert False, '%s not found in os.environ' % TEMP_NAME
def test_set_env_with_kwargs_updates(): test_env = {"TEST_ACME_TESTING_A": "a", "TEST_ACME_TESTING_B": "b", "TEST_ACME_TESTING_C": "c"} os.environ.update(test_env) with env.set_env("TEST_ACME_TESTING_A", 1, TEST_ACME_TESTING_B="fred", TEST_ACME_TESTING_C=None): assert os.environ["TEST_ACME_TESTING_A"] == "1" assert os.environ["TEST_ACME_TESTING_B"] == "fred" assert "C" not in os.environ assert os.environ["TEST_ACME_TESTING_A"] == "a" assert os.environ["TEST_ACME_TESTING_B"] == "b" assert os.environ["TEST_ACME_TESTING_C"] == "c"
def test_set_env_with_kwargs_updates(): test_env = { "TEST_ACME_TESTING_A": "a", "TEST_ACME_TESTING_B": "b", "TEST_ACME_TESTING_C": "c" } os.environ.update(test_env) with env.set_env("TEST_ACME_TESTING_A", 1, TEST_ACME_TESTING_B="fred", TEST_ACME_TESTING_C=None): assert os.environ["TEST_ACME_TESTING_A"] == "1" assert os.environ["TEST_ACME_TESTING_B"] == "fred" assert "C" not in os.environ assert os.environ["TEST_ACME_TESTING_A"] == "a" assert os.environ["TEST_ACME_TESTING_B"] == "b" assert os.environ["TEST_ACME_TESTING_C"] == "c"