Beispiel #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")
Beispiel #2
0
 def test_cp(self):
     system.echo("Hello, world!", "/tmp/labm8.tmp")
     self._test(["Hello, world!"], fs.read("/tmp/labm8.tmp"))
     # Cleanup any existing file.
     fs.rm("/tmp/labm8.tmp.copy")
     self._test(False, fs.exists("/tmp/labm8.tmp.copy"))
     fs.cp("/tmp/labm8.tmp", "/tmp/labm8.tmp.copy")
     self._test(fs.read("/tmp/labm8.tmp"), fs.read("/tmp/labm8.tmp.copy"))
Beispiel #3
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")
Beispiel #4
0
 def test_sed(self):
     system.echo("Hello, world!", "/tmp/labm8.tmp")
     system.sed("Hello", "Goodbye", "/tmp/labm8.tmp")
     self._test(["Goodbye, world!"], fs.read("/tmp/labm8.tmp"))
     system.sed("o", "_", "/tmp/labm8.tmp")
     self._test(["G_odbye, world!"], fs.read("/tmp/labm8.tmp"))
     system.sed("o", "_", "/tmp/labm8.tmp", "g")
     self._test(["G__dbye, w_rld!"], fs.read("/tmp/labm8.tmp"))
Beispiel #5
0
def test_scp_user():
  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="labm8/data/test/bin", user="******")
  assert fs.read("/tmp/labm8.tmp") == fs.read("/tmp/labm8.tmp.copy")
Beispiel #6
0
 def test_scp_user(self):
     system.echo("Hello, world!", "/tmp/labm8.tmp")
     self._test(["Hello, world!"], fs.read("/tmp/labm8.tmp"))
     # Cleanup any existing file.
     fs.rm("/tmp/labm8.tmp.copy")
     self._test(False, fs.exists("/tmp/labm8.tmp.copy"))
     # Perform scp.
     system.scp("localhost", "/tmp/labm8.tmp", "/tmp/labm8.tmp.copy",
                path="tests/bin", user="******")
     self._test(fs.read("/tmp/labm8.tmp"), fs.read("/tmp/labm8.tmp.copy"))
Beispiel #7
0
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()
Beispiel #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="labm8/data/test/bin")
Beispiel #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="labm8/data/test/bin")
Beispiel #10
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"))
Beispiel #11
0
 def test_cp_over_dir(self):
     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")
     self._test(True, fs.isdir("/tmp/labm8.tmp.src"))
     self._test(True, fs.isfile("/tmp/labm8.tmp.src/foo"))
     self._test(True, fs.isdir("/tmp/labm8.tmp.copy"))
     self._test(False, fs.isfile("/tmp/labm8.tmp.copy/foo"))
     fs.cp("/tmp/labm8.tmp.src", "/tmp/labm8.tmp.copy/")
     self._test(True, fs.isdir("/tmp/labm8.tmp.src"))
     self._test(True, fs.isfile("/tmp/labm8.tmp.src/foo"))
     self._test(True, fs.isdir("/tmp/labm8.tmp.copy"))
     self._test(True, fs.isfile("/tmp/labm8.tmp.copy/foo"))
     self._test(fs.read("/tmp/labm8.tmp.src/foo"),
                fs.read("/tmp/labm8.tmp.copy/foo"))
Beispiel #12
0
 def test_read(self):
     self._test(['Hello, world!'],
                fs.read("tests/data/hello_world"))
     self._test([
         '# data1 - test file',
         'This',
         'is a test file',
         'With',
         'trailing  # comment',
         '',
         '',
         '',
         'whitespace',
         '0.344'
     ],
                fs.read("tests/data/data1"))
Beispiel #13
0
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()
Beispiel #14
0
 def test_scp_bad_dst(self):
     system.echo("Hello, world!", "/tmp/labm8.tmp")
     self._test(["Hello, world!"], fs.read("/tmp/labm8.tmp"))
     # Error is raised if destination file cannot be written.
     with self.assertRaises(system.ScpError):
         system.scp("localhost", "/tmp/labm8.tmp", "/not/a/valid/path",
                    path="tests/bin")
Beispiel #15
0
 def test_scp_bad_dst_permission(self):
     system.echo("Hello, world!", "/tmp/labm8.tmp")
     self._test(["Hello, world!"], fs.read("/tmp/labm8.tmp"))
     # Error is raised if no write permission for destination.
     with self.assertRaises(system.ScpError):
         system.scp("localhost", "/tmp/labm8.tmp", "/dev",
                    path="tests/bin")
Beispiel #16
0
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()
Beispiel #17
0
    def test_dict_key(self):
        c = cache.FSCache("/tmp/labm8-cache-dict")

        # create file
        system.echo("Hello, world!", "/tmp/labm8.test.remove.txt")
        # sanity check
        self.assertEqual(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
        self.assertTrue(fs.read(c[key]),
                        ["Hello, world!"])
        c.clear()
Beispiel #18
0
    def test_set_and_get(self):
        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
        self.assertEqual(fs.read("/tmp/labm8.testfile.txt"),
                        ["Hello, world!"])

        # insert file into cache
        c['foobar'] = "/tmp/labm8.testfile.txt"

        # file must be in cache
        self.assertTrue(fs.isfile(c.keypath("foobar")))
        # file must have been moved
        self.assertFalse(fs.isfile("/tmp/labm8.testfile.txt"))
        # check file contents
        self.assertTrue(fs.read(c['foobar']), ["Hello, world!"])
        self.assertEqual(fs.read(c['foobar']), fs.read(c.get('foobar')))
        c.clear()
Beispiel #19
0
 def test_read_ignore_comments(self):
     self._test([
         'This',
         'is a test file',
         'With',
         'trailing',
         '',
         '',
         '',
         'whitespace',
         '0.344'
     ],
                fs.read("tests/data/data1", comment_char="#"))
Beispiel #20
0
    def test_remove(self):
        c = cache.FSCache("/tmp/labm8-cache-remove")

        # create file
        system.echo("Hello, world!", "/tmp/labm8.test.remove.txt")
        # sanity check
        self.assertEqual(fs.read("/tmp/labm8.test.remove.txt"),
                         ["Hello, world!"])

        # insert file into cache
        c['foobar'] = "/tmp/labm8.test.remove.txt"

        # sanity check
        self.assertEqual(fs.read(c['foobar']), ["Hello, world!"])

        # remove from cache
        del c['foobar']

        with self.assertRaises(KeyError):
            a = c['foobar']
        self.assertEqual(c.get("foobar"), None)
        c.clear()
Beispiel #21
0
 def test_read_no_rstrip(self):
     self._test([
         '# 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("tests/data/data1", rstrip=False))
Beispiel #22
0
 def test_read_ignore_comments_no_rstrip(self):
     self._test([
         'This\n',
         'is a test file\n',
         'With\n',
         'trailing  ',
         '\n',
         '\n',
         '\n',
         'whitespace\n',
         '0.344\n'
     ],
                fs.read("tests/data/data1",
                        rstrip=False, comment_char="#"))
Beispiel #23
0
 def test_echo(self):
     system.echo("foo", "/tmp/labm8.tmp")
     self._test(["foo"], fs.read("/tmp/labm8.tmp"))
     system.echo("", "/tmp/labm8.tmp")
     self._test([""], fs.read("/tmp/labm8.tmp"))
Beispiel #24
0
 def test_echo_append(self):
     system.echo("foo", "/tmp/labm8.tmp")
     system.echo("bar", "/tmp/labm8.tmp", append=True)
     self._test(["foo", "bar"], fs.read("/tmp/labm8.tmp"))
Beispiel #25
0
def test_read_ignore_comments():
    assert ([
        'This', 'is a test file', 'With', 'trailing', '', '', '', 'whitespace',
        '0.344'
    ] == fs.read("labm8/data/test/data1", comment_char="#"))
Beispiel #26
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("labm8/data/test/data1", rstrip=False))
Beispiel #27
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") == [""]
Beispiel #28
0
def test_echo_kwargs():
  system.echo("foo", "/tmp/labm8.tmp", end="_")
  assert fs.read("/tmp/labm8.tmp") == ["foo_"]
Beispiel #29
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("labm8/data/test/data1", rstrip=False, comment_char="#"))
Beispiel #30
0
def test_read_empty_file():
    assert fs.read("labm8/data/test/empty_file") == []
Beispiel #31
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"]
Beispiel #32
0
 def test_echo_kwargs(self):
     system.echo("foo", "/tmp/labm8.tmp", end="_")
     self._test(["foo_"], fs.read("/tmp/labm8.tmp"))
Beispiel #33
0
def test_read():
    assert ['Hello, world!'] == fs.read("labm8/data/test/hello_world")
    assert ([
        '# data1 - test file', 'This', 'is a test file', 'With',
        'trailing  # comment', '', '', '', 'whitespace', '0.344'
    ] == fs.read("labm8/data/test/data1"))
Beispiel #34
0
 def version(self) -> typing.Optional[str]:
     version_file = self.workspace_root / 'version.txt'
     if version_file.is_file():
         return fs.read(version_file).rstrip()
     else:
         return None
Beispiel #35
0
 def test_read_empty_file(self):
     self._test([],
                fs.read("tests/data/empty_file"))