def test_chdir_rug(tmpdir): """ Trying to chdir out af a non existent directory (i.e., one that was removed after we chdir'd into it) """ pytest.dbgfunc() origin = os.getcwd() rug = tmpdir.join('foo/bar/nosuch') rug.ensure(dir=True) with tbx.chdir(rug.strpath): shutil.rmtree(rug.dirname) with pytest.raises(OSError) as err: with tbx.chdir('..'): assert os.getcwd() == origin assert any([ 'No such file or directory' in str(err.value), 'Invalid argument' in str(err.value) ]) with pytest.raises(OSError) as err: assert os.getcwd() == rug.strpath assert os.getcwd() == origin assert any([ 'No such file or directory' in str(err.value), 'Invalid argument' in str(err.value) ])
def test_subst_rename_quiet(tmpdir, capsys): """ Test subst_rename() with dryrun False and quiet True. """ pytest.dbgfunc() with tbx.chdir(tmpdir.strpath): arglist = ['a.pl', 'b.pl', 'c.pl'] for a in arglist: tmpdir.join(a).ensure() expected = "".join([ 'rename %s.pl %s.xyzzy\n' % (x, x) for x in [q.replace('.pl', '') for q in arglist] ]) exp = [re.sub('.pl', '.xyzzy', x) for x in arglist] v = { '-n': False, '-q': True, '-e': True, 'SUBSTITUTION': "s/.pl/.xyzzy" } fx.subst_rename(v, arglist) assert expected in " ".join(capsys.readouterr()) q = glob.glob('*.pl') q.sort() assert [] == q q = glob.glob('*.xyzzy') q.sort() assert exp == q
def test_chdir_rug(tmpdir): """ Trying to chdir out af a non existent directory (i.e., one that was removed after we chdir'd into it) """ origin = os.getcwd() rug = tmpdir.join('foo/bar/nosuch') rug.ensure(dir=True) with tbx.chdir(rug.strpath): shutil.rmtree(rug.dirname) with pytest.raises(OSError) as err: with tbx.chdir('..'): assert os.getcwd() == origin assert 'No such file or directory' in str(err) with pytest.raises(OSError) as err: assert os.getcwd() == rug.strpath assert os.getcwd() == origin assert 'No such file or directory' in str(err)
def test_chdir_good(tmpdir): """ chdir(a.directory.that.exists) should work. After the with statement, we should be back where we started. """ orig = os.getcwd() with tbx.chdir(tmpdir.strpath): assert os.getcwd() == tmpdir.strpath assert orig == os.getcwd()
def test_abspath(tmpdir): """ Verify that tbx.abspath() behaves as expected """ pytest.dbgfunc() nib = tmpdir.join("testfile") nib.write("This is the test file") with tbx.chdir(tmpdir.strpath): assert tbx.abspath("./testfile") == nib.strpath
def test_chdir_nosuchdir(tmpdir): """ chdir(a.directory.that.does.not.exist) should throw an OSError with the message 'No such file or directory'. """ nosuch = tmpdir.join('foo/bar/somewhere') with pytest.raises(OSError) as err: with tbx.chdir(nosuch.strpath): assert os.getcwd() == tmpdir.strpath assert 'No such file or directory' in str(err)
def test_chdir_good(tmpdir): """ chdir(a.directory.that.exists) should work. After the with statement, we should be back where we started. """ pytest.dbgfunc() orig = os.getcwd() with tbx.chdir(tmpdir.strpath): assert os.getcwd() == tmpdir.strpath assert orig == os.getcwd()
def test_psys_quiet(tmpdir, capsys, data): """ Test routine psys with dryrun False and quiet True. """ pytest.dbgfunc() with tbx.chdir(tmpdir.strpath): exp = "a.xyzzy\nb.xyzzy\nc.xyzzy\ntmpfile\n" v = {'-n': False, '-q': True} fx.psys('ls', v) assert exp == "".join(capsys.readouterr())
def test_chdir_nosuchdir(tmpdir): """ chdir(a.directory.that.does.not.exist) should throw an OSError with the message 'No such file or directory'. """ pytest.dbgfunc() nosuch = tmpdir.join('foo/bar/somewhere') with pytest.raises(OSError) as err: with tbx.chdir(nosuch.strpath): assert os.getcwd() == tmpdir.strpath assert 'No such file or directory' in str(err.value)
def test_subst_command_dryrun(tmpdir, capsys): """ Test subst_command() with dryrun True and quiet False. """ pytest.dbgfunc() with tbx.chdir(tmpdir.strpath): v = {'-n': True, '-q': False, 'COMMAND': "ls %"} a = ['a.pl', 'b.pl', 'c.pl'] exp = "".join(["would do 'ls %s'\n" % x for x in a]) fx.subst_command(v, a) assert exp in " ".join(capsys.readouterr())
def test_subst_command_quiet(tmpdir, capsys): """ Test subst_command() with dryrun False and quiet True. """ pytest.dbgfunc() with tbx.chdir(tmpdir.strpath): v = {'-n': False, '-q': True, 'COMMAND': "ls %"} a = ['a.pl', 'b.pl', 'c.pl'] for x in a: tmpdir.join(x).ensure() exp = "".join(['%s\n' % x for x in a]) fx.subst_command(v, a) assert exp in " ".join(capsys.readouterr())
def test_iterate_command_quiet(tmpdir, capsys): """ Test iterate_command() with dryrun False and quiet True. """ pytest.dbgfunc() with tbx.chdir(tmpdir.strpath): v = { '-n': False, '-q': True, 'COMMAND': "echo %", '-i': True, 'RANGE': "5:10" } exp = "".join(["%d\n" % i for i in range(5, 10)]) fx.iterate_command(v, []) assert exp in "".join(capsys.readouterr())