1
from landscape.tests.helpers import LandscapeTest
3
from landscape.lib.fs import read_file, touch_file
6
class ReadFileTest(LandscapeTest):
8
def test_read_file(self):
10
With no options L{read_file} reads the whole file passed as argument.
12
path = self.makeFile("foo")
13
self.assertEquals(read_file(path), "foo")
15
def test_read_file_with_limit(self):
17
With a positive limit L{read_file} reads only the bytes after the
20
path = self.makeFile("foo bar")
21
self.assertEquals(read_file(path, limit=3), " bar")
23
def test_read_file_with_negative_limit(self):
25
With a negative limit L{read_file} reads only the tail of the file.
27
path = self.makeFile("foo bar from end")
28
self.assertEquals(read_file(path, limit=-3), "end")
30
def test_read_file_with_limit_bigger_than_file(self):
32
If the limit is bigger than the file L{read_file} reads the entire
35
path = self.makeFile("foo bar from end")
36
self.assertEquals(read_file(path, limit=100), "foo bar from end")
37
self.assertEquals(read_file(path, limit=-100), "foo bar from end")
40
class TouchFileTest(LandscapeTest):
42
def test_touch_file(self):
44
The L{touch_file} function touches a file, setting its last
47
path = self.makeFile()
48
uname_mock = self.mocker.replace("os.utime")
49
self.expect(uname_mock(path, None))
52
self.assertFileContent(path, "")
54
def test_touch_file_multiple_times(self):
56
The L{touch_file} function can be called multiple times.
58
path = self.makeFile()
61
self.assertFileContent(path, "")