Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e45c15

Browse files
TestOsOpsCommon is updated
New tests: - test_listdir - test_path_exists_true__directory - test_path_exists_true__file - test_path_exists_false__directory - test_path_exists_false__file - test_write_text_file - test_write_binary_file - test_read_text_file - test_read_binary_file
1 parent c2c2d4c commit 6e45c15

File tree

3 files changed

+119
-94
lines changed

3 files changed

+119
-94
lines changed

tests/test_local.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ def test_exec_command_failure__expect_error(self):
8585
assert b"nonexistent_command" in error
8686
assert b"not found" in error
8787

88-
def test_listdir(self):
89-
"""
90-
Test listdir for listing directory contents.
91-
"""
92-
path = "/etc"
93-
files = self.operations.listdir(path)
94-
assert isinstance(files, list)
95-
for f in files:
96-
assert f is not None
97-
assert type(f) == str # noqa: E721
98-
9988
def test_read__unknown_file(self):
10089
"""
10190
Test LocalOperations::read with unknown file.

tests/test_os_ops_common.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .helpers.os_ops_descrs import OsOpsDescr
33
from .helpers.os_ops_descrs import OsOpsDescrs
44
from .helpers.os_ops_descrs import OsOperations
5+
from .helpers.run_conditions import RunConditions
56

67
import os
78

@@ -27,6 +28,124 @@ def os_ops(self, request: pytest.FixtureRequest) -> OsOperations:
2728
assert isinstance(request.param, OsOperations)
2829
return request.param
2930

31+
def test_listdir(self, os_ops: OsOperations):
32+
"""
33+
Test listdir for listing directory contents.
34+
"""
35+
assert isinstance(os_ops, OsOperations)
36+
37+
RunConditions.skip_if_windows()
38+
39+
path = "/etc"
40+
files = os_ops.listdir(path)
41+
assert isinstance(files, list)
42+
for f in files:
43+
assert f is not None
44+
assert type(f) == str # noqa: E721
45+
46+
def test_path_exists_true__directory(self, os_ops: OsOperations):
47+
"""
48+
Test path_exists for an existing directory.
49+
"""
50+
assert isinstance(os_ops, OsOperations)
51+
52+
RunConditions.skip_if_windows()
53+
54+
assert os_ops.path_exists("/etc") is True
55+
56+
def test_path_exists_true__file(self, os_ops: OsOperations):
57+
"""
58+
Test path_exists for an existing file.
59+
"""
60+
assert isinstance(os_ops, OsOperations)
61+
62+
RunConditions.skip_if_windows()
63+
64+
assert os_ops.path_exists(__file__) is True
65+
66+
def test_path_exists_false__directory(self, os_ops: OsOperations):
67+
"""
68+
Test path_exists for a non-existing directory.
69+
"""
70+
assert isinstance(os_ops, OsOperations)
71+
72+
RunConditions.skip_if_windows()
73+
74+
assert os_ops.path_exists("/nonexistent_path") is False
75+
76+
def test_path_exists_false__file(self, os_ops: OsOperations):
77+
"""
78+
Test path_exists for a non-existing file.
79+
"""
80+
assert isinstance(os_ops, OsOperations)
81+
82+
RunConditions.skip_if_windows()
83+
84+
assert os_ops.path_exists("/etc/nonexistent_path.txt") is False
85+
86+
def test_write_text_file(self, os_ops: OsOperations):
87+
"""
88+
Test write for writing data to a text file.
89+
"""
90+
assert isinstance(os_ops, OsOperations)
91+
92+
RunConditions.skip_if_windows()
93+
94+
filename = "/tmp/test_file.txt"
95+
data = "Hello, world!"
96+
97+
os_ops.write(filename, data, truncate=True)
98+
os_ops.write(filename, data)
99+
100+
response = os_ops.read(filename)
101+
102+
assert response == data + data
103+
104+
def test_write_binary_file(self, os_ops: OsOperations):
105+
"""
106+
Test write for writing data to a binary file.
107+
"""
108+
assert isinstance(os_ops, OsOperations)
109+
110+
RunConditions.skip_if_windows()
111+
112+
filename = "/tmp/test_file.bin"
113+
data = b"\x00\x01\x02\x03"
114+
115+
os_ops.write(filename, data, binary=True, truncate=True)
116+
117+
response = os_ops.read(filename, binary=True)
118+
119+
assert response == data
120+
121+
def test_read_text_file(self, os_ops: OsOperations):
122+
"""
123+
Test read for reading data from a text file.
124+
"""
125+
assert isinstance(os_ops, OsOperations)
126+
127+
RunConditions.skip_if_windows()
128+
129+
filename = "/etc/hosts"
130+
131+
response = os_ops.read(filename)
132+
133+
assert isinstance(response, str)
134+
135+
def test_read_binary_file(self, os_ops: OsOperations):
136+
"""
137+
Test read for reading data from a binary file.
138+
"""
139+
assert isinstance(os_ops, OsOperations)
140+
141+
RunConditions.skip_if_windows()
142+
143+
filename = "/usr/bin/python3"
144+
145+
response = os_ops.read(filename, binary=True)
146+
147+
assert isinstance(response, bytes)
148+
30149
def test_read__text(self, os_ops: OsOperations):
31150
"""
32151
Test OsOperations::read for text data.

tests/test_remote.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33

44
import pytest
5-
import re
65
import logging
76

87
from ..testgres import ExecUtilException
@@ -214,88 +213,6 @@ def test_rmdirs__try_to_delete_file(self):
214213
assert type(x.value.exit_code) == int # noqa: E721
215214
assert x.value.exit_code == 20
216215

217-
def test_listdir(self):
218-
"""
219-
Test listdir for listing directory contents.
220-
"""
221-
path = "/etc"
222-
files = self.operations.listdir(path)
223-
assert isinstance(files, list)
224-
for f in files:
225-
assert f is not None
226-
assert type(f) == str # noqa: E721
227-
228-
def test_path_exists_true__directory(self):
229-
"""
230-
Test path_exists for an existing directory.
231-
"""
232-
assert self.operations.path_exists("/etc") is True
233-
234-
def test_path_exists_true__file(self):
235-
"""
236-
Test path_exists for an existing file.
237-
"""
238-
assert self.operations.path_exists(__file__) is True
239-
240-
def test_path_exists_false__directory(self):
241-
"""
242-
Test path_exists for a non-existing directory.
243-
"""
244-
assert self.operations.path_exists("/nonexistent_path") is False
245-
246-
def test_path_exists_false__file(self):
247-
"""
248-
Test path_exists for a non-existing file.
249-
"""
250-
assert self.operations.path_exists("/etc/nonexistent_path.txt") is False
251-
252-
def test_write_text_file(self):
253-
"""
254-
Test write for writing data to a text file.
255-
"""
256-
filename = "/tmp/test_file.txt"
257-
data = "Hello, world!"
258-
259-
self.operations.write(filename, data, truncate=True)
260-
self.operations.write(filename, data)
261-
262-
response = self.operations.read(filename)
263-
264-
assert response == data + data
265-
266-
def test_write_binary_file(self):
267-
"""
268-
Test write for writing data to a binary file.
269-
"""
270-
filename = "/tmp/test_file.bin"
271-
data = b"\x00\x01\x02\x03"
272-
273-
self.operations.write(filename, data, binary=True, truncate=True)
274-
275-
response = self.operations.read(filename, binary=True)
276-
277-
assert response == data
278-
279-
def test_read_text_file(self):
280-
"""
281-
Test read for reading data from a text file.
282-
"""
283-
filename = "/etc/hosts"
284-
285-
response = self.operations.read(filename)
286-
287-
assert isinstance(response, str)
288-
289-
def test_read_binary_file(self):
290-
"""
291-
Test read for reading data from a binary file.
292-
"""
293-
filename = "/usr/bin/python3"
294-
295-
response = self.operations.read(filename, binary=True)
296-
297-
assert isinstance(response, bytes)
298-
299216
def test_read__unknown_file(self):
300217
"""
301218
Test RemoteOperations::read with unknown file.

0 commit comments

Comments
 (0)