~gocept/landscape-client/py3-broker-amp-server

« back to all changes in this revision

Viewing changes to landscape/lib/tests/test_fs.py

  • Committer: 🤖 Landscape Builder
  • Author(s): Steffen Allner
  • Date: 2017-03-22 15:48:41 UTC
  • mfrom: (925.25.4 py3-changer)
  • Revision ID: _landscape_builder-20170322154841-8mjer06lt8c0y375
Merge py3-package-changer [f=] [r=landscape-builder,nilo,danilo] [a=Gocept]
Update tests for landscape.package.changer and improve landscape.lib.tests.test_fs tests to cover Unicode strings too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from landscape.tests.helpers import LandscapeTest
10
10
 
11
 
from landscape.lib.fs import append_text_file, touch_file
 
11
from landscape.lib.fs import append_text_file, append_binary_file, touch_file
12
12
from landscape.lib.fs import read_text_file, read_binary_file
13
13
 
14
14
 
98
98
        path = self.makeFile()
99
99
        touch_file(path)
100
100
        utime_mock.assert_called_once_with(path, None)
101
 
        self.assertFileContent(path, "")
 
101
        self.assertFileContent(path, b"")
102
102
 
103
103
    def test_touch_file_multiple_times(self):
104
104
        """
107
107
        path = self.makeFile()
108
108
        touch_file(path)
109
109
        touch_file(path)
110
 
        self.assertFileContent(path, "")
 
110
        self.assertFileContent(path, b"")
111
111
 
112
112
    def test_touch_file_with_offset_seconds(self):
113
113
        """
127
127
        utime_mock.assert_called_once_with(
128
128
            path, (expected_time, expected_time))
129
129
 
130
 
        self.assertFileContent(path, "")
 
130
        self.assertFileContent(path, b"")
131
131
 
132
132
 
133
133
class AppendFileTest(LandscapeTest):
137
137
        The L{append_text_file} function appends contents to an existing file.
138
138
        """
139
139
        existing_file = self.makeFile("foo bar")
140
 
        append_text_file(existing_file, " baz")
141
 
        self.assertFileContent(existing_file, "foo bar baz")
 
140
        append_text_file(existing_file, u" baz ☃")
 
141
        self.assertFileContent(existing_file, b"foo bar baz \xe2\x98\x83")
142
142
 
143
143
    def test_append_text_no_file(self):
144
144
        """
146
146
        exist already.
147
147
        """
148
148
        new_file = os.path.join(self.makeDir(), "new_file")
149
 
        append_text_file(new_file, "contents")
150
 
        self.assertFileContent(new_file, "contents")
 
149
        append_text_file(new_file, u"contents ☃")
 
150
        self.assertFileContent(new_file, b"contents \xe2\x98\x83")
151
151
 
152
152
    def test_append_existing_binary_file(self):
153
153
        """
154
154
        The L{append_text_file} function appends contents to an existing file.
155
155
        """
156
156
        existing_file = self.makeFile("foo bar")
157
 
        append_text_file(existing_file, " baz")
158
 
        self.assertFileContent(existing_file, "foo bar baz")
 
157
        append_binary_file(existing_file, b" baz \xe2\x98\x83")
 
158
        self.assertFileContent(existing_file, b"foo bar baz \xe2\x98\x83")
159
159
 
160
160
    def test_append_binary_no_file(self):
161
161
        """
163
163
        exist already.
164
164
        """
165
165
        new_file = os.path.join(self.makeDir(), "new_file")
166
 
        append_text_file(new_file, "contents")
167
 
        self.assertFileContent(new_file, "contents")
 
166
        append_binary_file(new_file, b"contents \xe2\x98\x83")
 
167
        self.assertFileContent(new_file, b"contents \xe2\x98\x83")