Skip to content

Commit 04d192e

Browse files
Merge pull request #166 from dmitry-lipetsk/D20241218_001--os_ops-isdir
OsOperations.isdir is added
2 parents 69b35cb + 38ce127 commit 04d192e

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed

testgres/operations/os_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def read_binary(self, filename, start_pos):
107107
def isfile(self, remote_file):
108108
raise NotImplementedError()
109109

110+
def isdir(self, dirname):
111+
raise NotImplementedError()
112+
110113
def get_file_size(self, filename):
111114
raise NotImplementedError()
112115

tests/test_local.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,67 @@ def test_get_file_size__unk_file(self):
118118

119119
with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
120120
self.operations.get_file_size("/dummy")
121+
122+
def test_isfile_true(self):
123+
"""
124+
Test isfile for an existing file.
125+
"""
126+
filename = __file__
127+
128+
response = self.operations.isfile(filename)
129+
130+
assert response is True
131+
132+
def test_isfile_false__not_exist(self):
133+
"""
134+
Test isfile for a non-existing file.
135+
"""
136+
filename = os.path.join(os.path.dirname(__file__), "nonexistent_file.txt")
137+
138+
response = self.operations.isfile(filename)
139+
140+
assert response is False
141+
142+
def test_isfile_false__directory(self):
143+
"""
144+
Test isfile for a firectory.
145+
"""
146+
name = os.path.dirname(__file__)
147+
148+
assert self.operations.isdir(name)
149+
150+
response = self.operations.isfile(name)
151+
152+
assert response is False
153+
154+
def test_isdir_true(self):
155+
"""
156+
Test isdir for an existing directory.
157+
"""
158+
name = os.path.dirname(__file__)
159+
160+
response = self.operations.isdir(name)
161+
162+
assert response is True
163+
164+
def test_isdir_false__not_exist(self):
165+
"""
166+
Test isdir for a non-existing directory.
167+
"""
168+
name = os.path.join(os.path.dirname(__file__), "it_is_nonexistent_directory")
169+
170+
response = self.operations.isdir(name)
171+
172+
assert response is False
173+
174+
def test_isdir_false__file(self):
175+
"""
176+
Test isdir for a file.
177+
"""
178+
name = __file__
179+
180+
assert self.operations.isfile(name)
181+
182+
response = self.operations.isdir(name)
183+
184+
assert response is False

tests/test_remote.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,62 @@ def test_isfile_true(self):
259259
"""
260260
Test isfile for an existing file.
261261
"""
262-
filename = "/etc/hosts"
262+
filename = __file__
263263

264264
response = self.operations.isfile(filename)
265265

266266
assert response is True
267267

268-
def test_isfile_false(self):
268+
def test_isfile_false__not_exist(self):
269269
"""
270270
Test isfile for a non-existing file.
271271
"""
272-
filename = "/nonexistent_file.txt"
272+
filename = os.path.join(os.path.dirname(__file__), "nonexistent_file.txt")
273273

274274
response = self.operations.isfile(filename)
275275

276276
assert response is False
277+
278+
def test_isfile_false__directory(self):
279+
"""
280+
Test isfile for a firectory.
281+
"""
282+
name = os.path.dirname(__file__)
283+
284+
assert self.operations.isdir(name)
285+
286+
response = self.operations.isfile(name)
287+
288+
assert response is False
289+
290+
def test_isdir_true(self):
291+
"""
292+
Test isdir for an existing directory.
293+
"""
294+
name = os.path.dirname(__file__)
295+
296+
response = self.operations.isdir(name)
297+
298+
assert response is True
299+
300+
def test_isdir_false__not_exist(self):
301+
"""
302+
Test isdir for a non-existing directory.
303+
"""
304+
name = os.path.join(os.path.dirname(__file__), "it_is_nonexistent_directory")
305+
306+
response = self.operations.isdir(name)
307+
308+
assert response is False
309+
310+
def test_isdir_false__file(self):
311+
"""
312+
Test isdir for a file.
313+
"""
314+
name = __file__
315+
316+
assert self.operations.isfile(name)
317+
318+
response = self.operations.isdir(name)
319+
320+
assert response is False

0 commit comments

Comments
 (0)