示例#1
0
def test_cp():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    assert ["Hello, world!"] == fs.read("/tmp/labm8.tmp")
    # Cleanup any existing file.
    fs.rm("/tmp/labm8.tmp.copy")
    assert not fs.exists("/tmp/labm8.tmp.copy")
    fs.cp("/tmp/labm8.tmp", "/tmp/labm8.tmp.copy")
    assert fs.read("/tmp/labm8.tmp") == fs.read("/tmp/labm8.tmp.copy")
示例#2
0
def test_sed():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    system.sed("Hello", "Goodbye", "/tmp/labm8.tmp")
    assert ["Goodbye, world!"] == fs.read("/tmp/labm8.tmp")
    system.sed("o", "_", "/tmp/labm8.tmp")
    assert ["G_odbye, world!"] == fs.read("/tmp/labm8.tmp")
    system.sed("o", "_", "/tmp/labm8.tmp", "g")
    assert ["G__dbye, w_rld!"] == fs.read("/tmp/labm8.tmp")
示例#3
0
def test_scp_bad_dst():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    assert ["Hello, world!"] == fs.read("/tmp/labm8.tmp")
    # Error is raised if destination file cannot be written.
    with pytest.raises(system.ScpError):
        system.scp("localhost",
                   "/tmp/labm8.tmp",
                   "/not/a/valid/path",
                   path="lib/labm8/data/test/bin")
示例#4
0
def test_scp_bad_dst_permission():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    assert ["Hello, world!"] == fs.read("/tmp/labm8.tmp")
    # Error is raised if no write permission for destination.
    with pytest.raises(system.ScpError):
        system.scp("localhost",
                   "/tmp/labm8.tmp",
                   "/dev",
                   path="lib/labm8/data/test/bin")
示例#5
0
def test_read_file():
    a_str = """{
          "a": 1,  // this has comments
          "b": [1, 2, 3]
      } # end comment
      // begin with comment
      """
    system.echo(a_str, "/tmp/labm8.loaf.json")
    a = jsonutil.read_file("/tmp/labm8.loaf.json")
    assert a == {'a': 1, 'b': [1, 2, 3]}
示例#6
0
def test_scp():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    assert ["Hello, world!"] == fs.read("/tmp/labm8.tmp")
    # Cleanup any existing file.
    fs.rm("/tmp/labm8.tmp.copy")
    assert not fs.exists("/tmp/labm8.tmp.copy")
    # Perform scp.
    system.scp("localhost",
               "/tmp/labm8.tmp",
               "/tmp/labm8.tmp.copy",
               path="lib/labm8/data/test/bin")
    assert fs.read("/tmp/labm8.tmp") == fs.read("/tmp/labm8.tmp.copy")
示例#7
0
文件: cache_test.py 项目: BeauJoh/phd
def test_FSCache_dict_key():
    c = cache.FSCache("/tmp/labm8-cache-dict")
    # create file
    system.echo("Hello, world!", "/tmp/labm8.test.remove.txt")
    # sanity check
    assert fs.read("/tmp/labm8.test.remove.txt") == ["Hello, world!"]
    # insert file into cache
    key = {'a': 5, "c": [1, 2, 3]}
    c[key] = "/tmp/labm8.test.remove.txt"
    # check file contents
    assert fs.read(c[key]) == ["Hello, world!"]
    c.clear()
示例#8
0
文件: cache_test.py 项目: BeauJoh/phd
def test_FSCache_iter_len():
    c = cache.FSCache("/tmp/labm8-fscache-iter", escape_key=cache.escape_path)
    c.clear()
    system.echo("Hello, world!", "/tmp/labm8.testfile.txt")
    c["foo"] = "/tmp/labm8.testfile.txt"
    for path in c:
        assert path == c.keypath("foo")
    system.echo("Hello, world!", "/tmp/labm8.testfile.txt")
    c["bar"] = "/tmp/labm8.testfile.txt"
    assert len(c) == 2
    assert len(c.ls()) == 2
    assert "bar" in c.ls()
    assert "foo" in c.ls()
    c.clear()
示例#9
0
def test_rm():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    assert fs.isfile("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.tmp")
    assert not fs.isfile("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.dir")
    fs.mkdir("/tmp/labm8.dir/foo/bar")
    system.echo("Hello, world!", "/tmp/labm8.dir/foo/bar/baz")
    assert fs.isfile("/tmp/labm8.dir/foo/bar/baz")
    fs.rm("/tmp/labm8.dir")
    assert not fs.isfile("/tmp/labm8.dir/foo/bar/baz")
    assert not fs.isfile("/tmp/labm8.dir/")
示例#10
0
def test_rmtrash():
    with tempfile.NamedTemporaryFile(prefix='labm8_') as f:
        assert fs.isfile(f.name)
        fs.rmtrash(f.name)
        assert not fs.isfile(f.name)
        fs.rmtrash(f.name)
        fs.rm(f.name)
    with tempfile.TemporaryDirectory() as d:
        fs.rm(d)
        fs.mkdir(d, "foo/bar")
        system.echo("Hello, world!", fs.path(d, "foo/bar/baz"))
        assert fs.isfile(f, "foo/bar/baz")
        fs.rmtrash(d)
        assert not fs.isfile(d, "foo/bar/baz")
        assert not fs.isdir(d)
示例#11
0
def test_cp_over_dir():
    fs.mkdir("/tmp/labm8.tmp.src")
    system.echo("Hello, world!", "/tmp/labm8.tmp.src/foo")
    fs.rm("/tmp/labm8.tmp.copy")
    fs.mkdir("/tmp/labm8.tmp.copy")
    assert fs.isdir("/tmp/labm8.tmp.src")
    assert fs.isfile("/tmp/labm8.tmp.src/foo")
    assert fs.isdir("/tmp/labm8.tmp.copy")
    assert not fs.isfile("/tmp/labm8.tmp.copy/foo")
    fs.cp("/tmp/labm8.tmp.src", "/tmp/labm8.tmp.copy/")
    assert fs.isdir("/tmp/labm8.tmp.src")
    assert fs.isfile("/tmp/labm8.tmp.src/foo")
    assert fs.isdir("/tmp/labm8.tmp.copy")
    assert fs.isfile("/tmp/labm8.tmp.copy/foo")
    assert (fs.read("/tmp/labm8.tmp.src/foo") == fs.read(
        "/tmp/labm8.tmp.copy/foo"))
示例#12
0
文件: cache_test.py 项目: BeauJoh/phd
def test_FSCache_remove():
    c = cache.FSCache("/tmp/labm8-cache-remove")
    # create file
    system.echo("Hello, world!", "/tmp/labm8.test.remove.txt")
    # sanity check
    assert fs.read("/tmp/labm8.test.remove.txt") == ["Hello, world!"]
    # insert file into cache
    c['foobar'] = "/tmp/labm8.test.remove.txt"
    # sanity check
    assert fs.read(c['foobar']) == ["Hello, world!"]
    # remove from cache
    del c['foobar']
    with pytest.raises(KeyError):
        c['foobar']
    assert not c.get("foobar")
    c.clear()
示例#13
0
文件: cache_test.py 项目: BeauJoh/phd
def test_set_and_get():
    fs.rm("/tmp/labm8-cache-set-and-get")
    c = cache.FSCache("/tmp/labm8-cache-set-and-get")
    # create file
    system.echo("Hello, world!", "/tmp/labm8.testfile.txt")
    # sanity check
    assert fs.read("/tmp/labm8.testfile.txt") == ["Hello, world!"]
    # insert file into cache
    c['foobar'] = "/tmp/labm8.testfile.txt"
    # file must be in cache
    assert fs.isfile(c.keypath("foobar"))
    # file must have been moved
    assert not fs.isfile("/tmp/labm8.testfile.txt")
    # check file contents
    assert fs.read(c['foobar']) == ["Hello, world!"]
    assert fs.read(c['foobar']) == fs.read(c.get('foobar'))
    c.clear()
示例#14
0
def test_rm_glob():
    fs.mkdir("/tmp/labm8.glob")
    system.echo("Hello, world!", "/tmp/labm8.glob/1")
    system.echo("Hello, world!", "/tmp/labm8.glob/2")
    system.echo("Hello, world!", "/tmp/labm8.glob/abc")

    fs.rm("/tmp/labm8.glob/a*", glob=False)
    assert fs.isfile("/tmp/labm8.glob/1")
    assert fs.isfile("/tmp/labm8.glob/2")
    assert fs.isfile("/tmp/labm8.glob/abc")

    fs.rm("/tmp/labm8.glob/a*")
    assert fs.isfile("/tmp/labm8.glob/1")
    assert fs.isfile("/tmp/labm8.glob/2")
    assert not fs.isfile("/tmp/labm8.glob/abc")

    fs.rm("/tmp/labm8.glob/*")
    assert not fs.isfile("/tmp/labm8.glob/1")
    assert not fs.isfile("/tmp/labm8.glob/2")
    assert not fs.isfile("/tmp/labm8.glob/abc")
示例#15
0
def test_echo_append():
    system.echo("foo", "/tmp/labm8.tmp")
    system.echo("bar", "/tmp/labm8.tmp", append=True)
    assert fs.read("/tmp/labm8.tmp") == ["foo", "bar"]
示例#16
0
def test_echo():
    system.echo("foo", "/tmp/labm8.tmp")
    assert fs.read("/tmp/labm8.tmp") == ["foo"]
    system.echo("", "/tmp/labm8.tmp")
    assert fs.read("/tmp/labm8.tmp") == [""]
示例#17
0
def test_mv_no_dst():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    with pytest.raises(IOError):
        fs.mv("/tmp/labm8.tmp", "/not/a/real/path")
    fs.rm("/tmp/labm8.tmp")
示例#18
0
def test_echo_kwargs():
    system.echo("foo", "/tmp/labm8.tmp", end="_")
    assert fs.read("/tmp/labm8.tmp") == ["foo_"]