|
1 | 1 | import os
|
2 | 2 |
|
3 | 3 | import pytest
|
| 4 | +import re |
4 | 5 |
|
5 | 6 | from testgres import ExecUtilException
|
6 | 7 | from testgres import RemoteOperations
|
@@ -181,6 +182,48 @@ def test_read_binary_file(self):
|
181 | 182 |
|
182 | 183 | assert isinstance(response, bytes)
|
183 | 184 |
|
| 185 | + def test_read_binary__spec(self): |
| 186 | + """ |
| 187 | + Test RemoteOperations::read_binary. |
| 188 | + """ |
| 189 | + filename = __file__ # currnt file |
| 190 | + |
| 191 | + with open(filename, 'rb') as file: # open in a binary mode |
| 192 | + response0 = file.read() |
| 193 | + |
| 194 | + assert type(response0) == bytes # noqa: E721 |
| 195 | + |
| 196 | + response1 = self.operations.read_binary(filename, 0) |
| 197 | + assert type(response1) == bytes # noqa: E721 |
| 198 | + assert response1 == response0 |
| 199 | + |
| 200 | + response2 = self.operations.read_binary(filename, 1) |
| 201 | + assert type(response2) == bytes # noqa: E721 |
| 202 | + assert len(response2) < len(response1) |
| 203 | + assert len(response2) + 1 == len(response1) |
| 204 | + assert response2 == response1[1:] |
| 205 | + |
| 206 | + response3 = self.operations.read_binary(filename, len(response1)) |
| 207 | + assert type(response3) == bytes # noqa: E721 |
| 208 | + assert len(response3) == 0 |
| 209 | + |
| 210 | + response4 = self.operations.read_binary(filename, len(response2)) |
| 211 | + assert type(response4) == bytes # noqa: E721 |
| 212 | + assert len(response4) == 1 |
| 213 | + assert response4[0] == response1[len(response1) - 1] |
| 214 | + |
| 215 | + response5 = self.operations.read_binary(filename, len(response1) + 1) |
| 216 | + assert type(response5) == bytes # noqa: E721 |
| 217 | + assert len(response5) == 0 |
| 218 | + |
| 219 | + def test_read_binary__spec__unk_file(self): |
| 220 | + """ |
| 221 | + Test RemoteOperations::read_binary with unknown file. |
| 222 | + """ |
| 223 | + |
| 224 | + with pytest.raises(ExecUtilException, match=re.escape("tail: cannot open '/dummy' for reading: No such file or directory")): |
| 225 | + self.operations.read_binary("/dummy", 0) |
| 226 | + |
184 | 227 | def test_touch(self):
|
185 | 228 | """
|
186 | 229 | Test touch for creating a new file or updating access and modification times of an existing file.
|
|
0 commit comments