コード例 #1
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")
コード例 #2
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")
コード例 #3
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")
コード例 #4
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()
コード例 #5
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"))
コード例 #6
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()
コード例 #7
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()
コード例 #8
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")
コード例 #9
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")
コード例 #10
0
def test_echo_kwargs():
    system.echo("foo", "/tmp/labm8.tmp", end="_")
    assert fs.read("/tmp/labm8.tmp") == ["foo_"]
コード例 #11
0
def test_read_no_rstrip():
    assert ([
        '# data1 - test file\n', 'This\n', 'is a test file\n', 'With\n',
        'trailing  # comment  \n', '\n', '\n', '\n', 'whitespace\n', '0.344\n'
    ] == fs.read("lib/labm8/data/test/data1", rstrip=False))
コード例 #12
0
def test_read_empty_file():
    assert fs.read("lib/labm8/data/test/empty_file") == []
コード例 #13
0
def test_read_ignore_comments_no_rstrip():
    assert ([
        'This\n', 'is a test file\n', 'With\n', 'trailing  ', '\n', '\n', '\n',
        'whitespace\n', '0.344\n'
    ] == fs.read("lib/labm8/data/test/data1", rstrip=False, comment_char="#"))
コード例 #14
0
def test_read_ignore_comments():
    assert ([
        'This', 'is a test file', 'With', 'trailing', '', '', '', 'whitespace',
        '0.344'
    ] == fs.read("lib/labm8/data/test/data1", comment_char="#"))
コード例 #15
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") == [""]
コード例 #16
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"]
コード例 #17
0
def test_read():
    assert ['Hello, world!'] == fs.read("lib/labm8/data/test/hello_world")
    assert ([
        '# data1 - test file', 'This', 'is a test file', 'With',
        'trailing  # comment', '', '', '', 'whitespace', '0.344'
    ] == fs.read("lib/labm8/data/test/data1"))