def test_task_proj(tasks): """ Given some tasks, report them and verify that they have whitespace between them """ pytest.dbgfunc() tmpdir = tasks['tmpdir'] kw = { 'PROJECT': 'myproj', 'count': False, 'd': False, 's': None, 'projects': False, 'tasks': True, 'version': False } with tbx.envset(GH_ROOT=tmpdir.strpath): result = ghm.gh_tasks_t(**kw) assert "\n\n - " in result kw = { 'PROJECT': 'nosuch', 'count': False, 'd': False, 's': None, 'projects': False, 'tasks': True, 'version': False } with tbx.envset(GH_ROOT=tmpdir.strpath): result = ghm.gh_tasks_t(**kw) assert result == ""
def test_envset_new_1(): """ Set a single new environment variable """ if os.getenv('TEST_ENVSET'): del os.environ['TEST_ENVSET'] with tbx.envset(TEST_ENVSET='foobar'): assert os.getenv('TEST_ENVSET') == 'foobar' assert os.getenv('TEST_ENVSET') is None
def test_envset_old_1(): """ Set a single existing environment variable to a new value """ pytest.dbgfunc() orig = os.getenv('HOME') with tbx.envset(HOME='/somewhere/over/the/rainbow'): assert os.getenv('HOME') == '/somewhere/over/the/rainbow' assert os.getenv('HOME') == orig
def test_envset_old_1(): """ Set a single existing environment variable to a new value """ assert os.getenv('HOME') is not None orig = os.getenv('HOME') with tbx.envset(HOME='/somewhere/over/the/rainbow'): assert os.getenv('HOME') == '/somewhere/over/the/rainbow' assert os.getenv('HOME') == orig
def test_xw_sub(cmd, item, exp): """ If a '%' appears in cmd, determine the word it appears in and then replace that word with the item followed by the % word. By calling xw_sub repeatedly, we can stuff item after item into the original command string. """ pytest.dbgfunc() with tbx.envset(HOME='/home/dir', USER='******'): assert fx.xw_sub(cmd, item) == exp
def test_expand(inp, exp): """ Expand all environment variables, then expand '~' into $HOME. Note: os.path.expanduser() only expands '~' if it's at the beginning of the string (not what I want) """ pytest.dbgfunc() with tbx.envset(HOME='/home/dir', FOO='my home dir = ~', EVAR='value'): assert tbx.expand(inp) == exp
def test_envset_new_1(): """ Set a single new environment variable """ pytest.dbgfunc() if os.getenv('TEST_ENVSET'): del os.environ['TEST_ENVSET'] with tbx.envset(TEST_ENVSET='foobar'): assert os.getenv('TEST_ENVSET') == 'foobar' assert os.getenv('TEST_ENVSET') is None
def test_envset_new_none(): """ Set a new environment variable to None """ pytest.dbgfunc() vname = 'TEST_ENVSET' if os.getenv(vname): del os.environ[vname] with tbx.envset(TEST_ENVSET=None): assert os.getenv(vname) is None assert os.getenv(vname) is None
def test_envset_rm(): """ Temporarily unset an environment variable """ vname = 'TEST_ENVSET_RM' origval = 'original value' kwa = {vname: None} os.environ[vname] = origval with tbx.envset(**kwa): assert os.getenv(vname) is None assert os.getenv(vname) == origval del os.environ[vname]
def test_envset_child(): """ If we set an env var with envset, then spawn a process, the new setting should show up in the child process. """ pytest.dbgfunc() result = tbx.run("env") assert "TBX_TEST=gargantuan" not in result with tbx.envset(TBX_TEST="gargantuan"): result = tbx.run("env") assert "TBX_TEST=gargantuan" in result result = tbx.run("env") assert "TBX_TEST=gargantuan" not in result
def test_envset_rm(): """ Temporarily unset an environment variable """ pytest.dbgfunc() vname = 'TEST_ENVSET_RM' origval = 'original value' kwa = {vname: None} os.environ[vname] = origval with tbx.envset(**kwa): assert os.getenv(vname) is None assert os.getenv(vname) == origval del os.environ[vname]
def test_envset_old_2(): """ Set multiple new environment variables """ vlist = ['HOME', 'TERM'] orig = {} for varname in vlist: orig[varname] = os.getenv(varname) with tbx.envset(HOME='new-value', TERM='not-the-old-value'): assert os.getenv('HOME') == 'new-value' assert os.getenv('TERM') == 'not-the-old-value' assert os.getenv('HOME') == orig['HOME'] assert os.getenv('TERM') == orig['TERM']
def test_envset_old_2(): """ Set multiple new environment variables """ pytest.dbgfunc() vlist = ['HOME', 'TERM'] orig = {} for varname in vlist: orig[varname] = os.getenv(varname) with tbx.envset(HOME='new-value', TERM='not-the-old-value'): assert os.getenv('HOME') == 'new-value' assert os.getenv('TERM') == 'not-the-old-value' assert os.getenv('HOME') == orig['HOME'] assert os.getenv('TERM') == orig['TERM']
def test_envset_new_2(): """ Set multiple new environment variables """ pytest.dbgfunc() vlist = ['TEST_ENVSET', 'TEST_ENVSET_2'] for varname in vlist: if os.getenv(varname): del os.environ[varname] with tbx.envset(TEST_ENVSET='foobar', TEST_ENVSET_2='yetanother'): assert os.getenv('TEST_ENVSET') == 'foobar' assert os.getenv('TEST_ENVSET_2') == 'yetanother' assert os.getenv('TEST_ENVSET') is None assert os.getenv('TEST_ENVSET_2') is None
def test_envset_new_2(): """ Set multiple new environment variables """ vlist = ['TEST_ENVSET', 'TEST_ENVSET_2'] for varname in vlist: if os.getenv(varname): del os.environ[varname] with tbx.envset(TEST_ENVSET='foobar', TEST_ENVSET_2='yetanother'): assert os.getenv('TEST_ENVSET') == 'foobar' assert os.getenv('TEST_ENVSET_2') == 'yetanother' assert os.getenv('TEST_ENVSET') is None assert os.getenv('TEST_ENVSET_2') is None
def test_envset_rmset(): """ Temporarily set one environment variable and unset another one """ keys = ['TEST_ENVSET_RM', 'TEST_ENVSET_SET'] origval = dict(zip(keys, ['something', 'something else'])) updval = dict(zip(keys, [None, 'different from the first'])) for key in keys: os.environ[key] = origval[key] with tbx.envset(**updval): for key in keys: assert os.getenv(key) == updval[key] for key in keys: assert os.getenv(key) == origval[key] for key in keys: del os.environ[key]
def test_envset_rmset(): """ Temporarily set one environment variable and unset another one """ pytest.dbgfunc() keys = ['TEST_ENVSET_RM', 'TEST_ENVSET_SET'] origval = dict(zip(keys, ['something', 'something else'])) updval = dict(zip(keys, [None, 'different from the first'])) for key in keys: os.environ[key] = origval[key] with tbx.envset(**updval): for key in keys: assert os.getenv(key) == updval[key] for key in keys: assert os.getenv(key) == origval[key] for key in keys: del os.environ[key]
def test_projects_count(prjdirs): """ Test for ghm.gh_projects_t(), verifying that projects with no dodo file are identified """ pytest.dbgfunc() tmpdir = prjdirs['root'] kw = { 'PROJECT': None, 'count': True, 'd': False, 's': None, 'projects': True, 'tasks': False, 'version': False } with tbx.envset(GH_ROOT=tmpdir.strpath): result = ghm.gh_projects_t(**kw) exp = "{} projects found\n".format(len(prjdirs['input'])) assert result == exp
def test_projects_t(prjdirs): """ Test for ghm.gh_projects_t(), verifying that projects with no dodo file are identified """ pytest.dbgfunc() tmpdir = prjdirs['root'] kw = { 'PROJECT': None, 'count': False, 'd': False, 's': None, 'projects': True, 'tasks': False, 'version': False } with tbx.envset(GH_ROOT=tmpdir.strpath): result = ghm.gh_projects_t(**kw) assert "nododo (no DODO)" in result assert "tbx" in result assert "tbx (no DODO)" not in result
def test_task_count(tasks): """ Given some tasks, report them and verify that they have whitespace between them """ pytest.dbgfunc() tmpdir = tasks['tmpdir'] kw = { 'PROJECT': 'myproj', 'count': True, 'd': False, 's': None, 'projects': False, 'tasks': True, 'version': False } with tbx.envset(GH_ROOT=tmpdir.strpath): result = ghm.gh_tasks_t(**kw) rgx = r"\s+{}\s+4\n".format(tasks['prj']) assert re.search(rgx, result) assert re.search(r"\s+Total\s+4\n", result)