Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a19e0b

Browse files
TestOsOpsCommon is added [generic os_ops tests] (#231)
Plus: - [BUG FIX] LocalOperations::is_executable is corrected - [FIX] OsOperations::mkstemp is added
1 parenta9137df commit5a19e0b

File tree

5 files changed

+655
-851
lines changed

5 files changed

+655
-851
lines changed

‎testgres/operations/local_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def find_executable(self, executable):
156156

157157
defis_executable(self,file):
158158
# Check if the file is executable
159-
returnos.stat(file).st_mode&stat.S_IXUSR
159+
assertstat.S_IXUSR!=0
160+
return (os.stat(file).st_mode&stat.S_IXUSR)==stat.S_IXUSR
160161

161162
defset_env(self,var_name,var_val):
162163
# Check if the directory is already in PATH

‎testgres/operations/os_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def pathsep(self):
7777
defmkdtemp(self,prefix=None):
7878
raiseNotImplementedError()
7979

80+
defmkstemp(self,prefix=None):
81+
raiseNotImplementedError()
82+
8083
defcopytree(self,src,dst):
8184
raiseNotImplementedError()
8285

‎tests/test_local.py

Lines changed: 0 additions & 327 deletions
Original file line numberDiff line numberDiff line change
@@ -3,154 +3,16 @@
33

44
importpytest
55
importre
6-
importtempfile
7-
importlogging
86

9-
from ..testgresimportExecUtilException
10-
from ..testgresimportInvalidOperationException
117
from ..testgresimportLocalOperations
128

13-
from .helpers.run_conditionsimportRunConditions
14-
159

1610
classTestLocalOperations:
1711

1812
@pytest.fixture(scope="function",autouse=True)
1913
defsetup(self):
2014
self.operations=LocalOperations()
2115

22-
deftest_mkdtemp__default(self):
23-
path=self.operations.mkdtemp()
24-
logging.info("Path is [{0}].".format(path))
25-
assertos.path.exists(path)
26-
os.rmdir(path)
27-
assertnotos.path.exists(path)
28-
29-
deftest_mkdtemp__custom(self):
30-
C_TEMPLATE="abcdef"
31-
path=self.operations.mkdtemp(C_TEMPLATE)
32-
logging.info("Path is [{0}].".format(path))
33-
assertos.path.exists(path)
34-
assertC_TEMPLATEinos.path.basename(path)
35-
os.rmdir(path)
36-
assertnotos.path.exists(path)
37-
38-
deftest_exec_command_success(self):
39-
"""
40-
Test exec_command for successful command execution.
41-
"""
42-
RunConditions.skip_if_windows()
43-
44-
cmd="python3 --version"
45-
response=self.operations.exec_command(cmd,wait_exit=True,shell=True)
46-
47-
assertb'Python 3.'inresponse
48-
49-
deftest_exec_command_failure(self):
50-
"""
51-
Test exec_command for command execution failure.
52-
"""
53-
RunConditions.skip_if_windows()
54-
55-
cmd="nonexistent_command"
56-
whileTrue:
57-
try:
58-
self.operations.exec_command(cmd,wait_exit=True,shell=True)
59-
exceptExecUtilExceptionase:
60-
asserttype(e.exit_code)==int# noqa: E721
61-
asserte.exit_code==127
62-
63-
asserttype(e.message)==str# noqa: E721
64-
asserttype(e.error)==bytes# noqa: E721
65-
66-
asserte.message.startswith("Utility exited with non-zero code (127). Error:")
67-
assert"nonexistent_command"ine.message
68-
assert"not found"ine.message
69-
assertb"nonexistent_command"ine.error
70-
assertb"not found"ine.error
71-
break
72-
raiseException("We wait an exception!")
73-
74-
deftest_exec_command_failure__expect_error(self):
75-
"""
76-
Test exec_command for command execution failure.
77-
"""
78-
RunConditions.skip_if_windows()
79-
80-
cmd="nonexistent_command"
81-
82-
exit_status,result,error=self.operations.exec_command(cmd,verbose=True,wait_exit=True,shell=True,expect_error=True)
83-
84-
assertexit_status==127
85-
assertresult==b''
86-
asserttype(error)==bytes# noqa: E721
87-
assertb"nonexistent_command"inerror
88-
assertb"not found"inerror
89-
90-
deftest_listdir(self):
91-
"""
92-
Test listdir for listing directory contents.
93-
"""
94-
path="/etc"
95-
files=self.operations.listdir(path)
96-
assertisinstance(files,list)
97-
forfinfiles:
98-
assertfisnotNone
99-
asserttype(f)==str# noqa: E721
100-
101-
deftest_read__text(self):
102-
"""
103-
Test LocalOperations::read for text data.
104-
"""
105-
filename=__file__# current file
106-
107-
withopen(filename,'r')asfile:# open in a text mode
108-
response0=file.read()
109-
110-
asserttype(response0)==str# noqa: E721
111-
112-
response1=self.operations.read(filename)
113-
asserttype(response1)==str# noqa: E721
114-
assertresponse1==response0
115-
116-
response2=self.operations.read(filename,encoding=None,binary=False)
117-
asserttype(response2)==str# noqa: E721
118-
assertresponse2==response0
119-
120-
response3=self.operations.read(filename,encoding="")
121-
asserttype(response3)==str# noqa: E721
122-
assertresponse3==response0
123-
124-
response4=self.operations.read(filename,encoding="UTF-8")
125-
asserttype(response4)==str# noqa: E721
126-
assertresponse4==response0
127-
128-
deftest_read__binary(self):
129-
"""
130-
Test LocalOperations::read for binary data.
131-
"""
132-
filename=__file__# current file
133-
134-
withopen(filename,'rb')asfile:# open in a binary mode
135-
response0=file.read()
136-
137-
asserttype(response0)==bytes# noqa: E721
138-
139-
response1=self.operations.read(filename,binary=True)
140-
asserttype(response1)==bytes# noqa: E721
141-
assertresponse1==response0
142-
143-
deftest_read__binary_and_encoding(self):
144-
"""
145-
Test LocalOperations::read for binary data and encoding.
146-
"""
147-
filename=__file__# current file
148-
149-
withpytest.raises(
150-
InvalidOperationException,
151-
match=re.escape("Enconding is not allowed for read binary operation")):
152-
self.operations.read(filename,encoding="",binary=True)
153-
15416
deftest_read__unknown_file(self):
15517
"""
15618
Test LocalOperations::read with unknown file.
@@ -159,40 +21,6 @@ def test_read__unknown_file(self):
15921
withpytest.raises(FileNotFoundError,match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
16022
self.operations.read("/dummy")
16123

162-
deftest_read_binary__spec(self):
163-
"""
164-
Test LocalOperations::read_binary.
165-
"""
166-
filename=__file__# current file
167-
168-
withopen(filename,'rb')asfile:# open in a binary mode
169-
response0=file.read()
170-
171-
asserttype(response0)==bytes# noqa: E721
172-
173-
response1=self.operations.read_binary(filename,0)
174-
asserttype(response1)==bytes# noqa: E721
175-
assertresponse1==response0
176-
177-
response2=self.operations.read_binary(filename,1)
178-
asserttype(response2)==bytes# noqa: E721
179-
assertlen(response2)<len(response1)
180-
assertlen(response2)+1==len(response1)
181-
assertresponse2==response1[1:]
182-
183-
response3=self.operations.read_binary(filename,len(response1))
184-
asserttype(response3)==bytes# noqa: E721
185-
assertlen(response3)==0
186-
187-
response4=self.operations.read_binary(filename,len(response2))
188-
asserttype(response4)==bytes# noqa: E721
189-
assertlen(response4)==1
190-
assertresponse4[0]==response1[len(response1)-1]
191-
192-
response5=self.operations.read_binary(filename,len(response1)+1)
193-
asserttype(response5)==bytes# noqa: E721
194-
assertlen(response5)==0
195-
19624
deftest_read_binary__spec__unk_file(self):
19725
"""
19826
Test LocalOperations::read_binary with unknown file.
@@ -203,29 +31,6 @@ def test_read_binary__spec__unk_file(self):
20331
match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
20432
self.operations.read_binary("/dummy",0)
20533

206-
deftest_read_binary__spec__negative_offset(self):
207-
"""
208-
Test LocalOperations::read_binary with negative offset.
209-
"""
210-
211-
withpytest.raises(
212-
ValueError,
213-
match=re.escape("Negative 'offset' is not supported.")):
214-
self.operations.read_binary(__file__,-1)
215-
216-
deftest_get_file_size(self):
217-
"""
218-
Test LocalOperations::get_file_size.
219-
"""
220-
filename=__file__# current file
221-
222-
sz0=os.path.getsize(filename)
223-
asserttype(sz0)==int# noqa: E721
224-
225-
sz1=self.operations.get_file_size(filename)
226-
asserttype(sz1)==int# noqa: E721
227-
assertsz1==sz0
228-
22934
deftest_get_file_size__unk_file(self):
23035
"""
23136
Test LocalOperations::get_file_size.
@@ -234,70 +39,6 @@ def test_get_file_size__unk_file(self):
23439
withpytest.raises(FileNotFoundError,match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
23540
self.operations.get_file_size("/dummy")
23641

237-
deftest_isfile_true(self):
238-
"""
239-
Test isfile for an existing file.
240-
"""
241-
filename=__file__
242-
243-
response=self.operations.isfile(filename)
244-
245-
assertresponseisTrue
246-
247-
deftest_isfile_false__not_exist(self):
248-
"""
249-
Test isfile for a non-existing file.
250-
"""
251-
filename=os.path.join(os.path.dirname(__file__),"nonexistent_file.txt")
252-
253-
response=self.operations.isfile(filename)
254-
255-
assertresponseisFalse
256-
257-
deftest_isfile_false__directory(self):
258-
"""
259-
Test isfile for a firectory.
260-
"""
261-
name=os.path.dirname(__file__)
262-
263-
assertself.operations.isdir(name)
264-
265-
response=self.operations.isfile(name)
266-
267-
assertresponseisFalse
268-
269-
deftest_isdir_true(self):
270-
"""
271-
Test isdir for an existing directory.
272-
"""
273-
name=os.path.dirname(__file__)
274-
275-
response=self.operations.isdir(name)
276-
277-
assertresponseisTrue
278-
279-
deftest_isdir_false__not_exist(self):
280-
"""
281-
Test isdir for a non-existing directory.
282-
"""
283-
name=os.path.join(os.path.dirname(__file__),"it_is_nonexistent_directory")
284-
285-
response=self.operations.isdir(name)
286-
287-
assertresponseisFalse
288-
289-
deftest_isdir_false__file(self):
290-
"""
291-
Test isdir for a file.
292-
"""
293-
name=__file__
294-
295-
assertself.operations.isfile(name)
296-
297-
response=self.operations.isdir(name)
298-
299-
assertresponseisFalse
300-
30142
deftest_cwd(self):
30243
"""
30344
Test cwd.
@@ -314,71 +55,3 @@ def test_cwd(self):
31455

31556
# Comp result
31657
assertv==expectedValue
317-
318-
classtagWriteData001:
319-
def__init__(self,sign,source,cp_rw,cp_truncate,cp_binary,cp_data,result):
320-
self.sign=sign
321-
self.source=source
322-
self.call_param__rw=cp_rw
323-
self.call_param__truncate=cp_truncate
324-
self.call_param__binary=cp_binary
325-
self.call_param__data=cp_data
326-
self.result=result
327-
328-
sm_write_data001= [
329-
tagWriteData001("A001","1234567890",False,False,False,"ABC","1234567890ABC"),
330-
tagWriteData001("A002",b"1234567890",False,False,True,b"ABC",b"1234567890ABC"),
331-
332-
tagWriteData001("B001","1234567890",False,True,False,"ABC","ABC"),
333-
tagWriteData001("B002","1234567890",False,True,False,"ABC1234567890","ABC1234567890"),
334-
tagWriteData001("B003",b"1234567890",False,True,True,b"ABC",b"ABC"),
335-
tagWriteData001("B004",b"1234567890",False,True,True,b"ABC1234567890",b"ABC1234567890"),
336-
337-
tagWriteData001("C001","1234567890",True,False,False,"ABC","1234567890ABC"),
338-
tagWriteData001("C002",b"1234567890",True,False,True,b"ABC",b"1234567890ABC"),
339-
340-
tagWriteData001("D001","1234567890",True,True,False,"ABC","ABC"),
341-
tagWriteData001("D002","1234567890",True,True,False,"ABC1234567890","ABC1234567890"),
342-
tagWriteData001("D003",b"1234567890",True,True,True,b"ABC",b"ABC"),
343-
tagWriteData001("D004",b"1234567890",True,True,True,b"ABC1234567890",b"ABC1234567890"),
344-
345-
tagWriteData001("E001","\0001234567890\000",False,False,False,"\000ABC\000","\0001234567890\000\000ABC\000"),
346-
tagWriteData001("E002",b"\0001234567890\000",False,False,True,b"\000ABC\000",b"\0001234567890\000\000ABC\000"),
347-
348-
tagWriteData001("F001","a\nb\n",False,False,False, ["c","d"],"a\nb\nc\nd\n"),
349-
tagWriteData001("F002",b"a\nb\n",False,False,True, [b"c",b"d"],b"a\nb\nc\nd\n"),
350-
351-
tagWriteData001("G001","a\nb\n",False,False,False, ["c\n\n","d\n"],"a\nb\nc\nd\n"),
352-
tagWriteData001("G002",b"a\nb\n",False,False,True, [b"c\n\n",b"d\n"],b"a\nb\nc\nd\n"),
353-
]
354-
355-
@pytest.fixture(
356-
params=sm_write_data001,
357-
ids=[x.signforxinsm_write_data001],
358-
)
359-
defwrite_data001(self,request):
360-
assertisinstance(request,pytest.FixtureRequest)
361-
asserttype(request.param)==__class__.tagWriteData001# noqa: E721
362-
returnrequest.param
363-
364-
deftest_write(self,write_data001):
365-
asserttype(write_data001)==__class__.tagWriteData001# noqa: E721
366-
367-
mode="w+b"ifwrite_data001.call_param__binaryelse"w+"
368-
369-
withtempfile.NamedTemporaryFile(mode=mode,delete=True)astmp_file:
370-
tmp_file.write(write_data001.source)
371-
tmp_file.flush()
372-
373-
self.operations.write(
374-
tmp_file.name,
375-
write_data001.call_param__data,
376-
read_and_write=write_data001.call_param__rw,
377-
truncate=write_data001.call_param__truncate,
378-
binary=write_data001.call_param__binary)
379-
380-
tmp_file.seek(0)
381-
382-
s=tmp_file.read()
383-
384-
asserts==write_data001.result

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp