2
2
from .helpers .os_ops_descrs import OsOpsDescr
3
3
from .helpers .os_ops_descrs import OsOpsDescrs
4
4
from .helpers .os_ops_descrs import OsOperations
5
+ from .helpers .run_conditions import RunConditions
5
6
6
7
import os
7
8
@@ -27,6 +28,124 @@ def os_ops(self, request: pytest.FixtureRequest) -> OsOperations:
27
28
assert isinstance (request .param , OsOperations )
28
29
return request .param
29
30
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
+
30
149
def test_read__text (self , os_ops : OsOperations ):
31
150
"""
32
151
Test OsOperations::read for text data.
0 commit comments