示例#1
0
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)
    ])
示例#2
0
文件: test_fx.py 项目: tbarron/fx
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
示例#3
0
文件: test_tbx.py 项目: tbarron/tbx
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)
示例#4
0
文件: test_tbx.py 项目: tbarron/tbx
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()
示例#5
0
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
示例#6
0
文件: test_tbx.py 项目: tbarron/tbx
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)
示例#7
0
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()
示例#8
0
文件: test_fx.py 项目: tbarron/fx
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())
示例#9
0
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)
示例#10
0
文件: test_fx.py 项目: tbarron/fx
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())
示例#11
0
文件: test_fx.py 项目: tbarron/fx
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())
示例#12
0
文件: test_fx.py 项目: tbarron/fx
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())