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

Commit75b0804

Browse files
TestOsOpsCommon is added [generic os_ops tests]
1 parenta9137df commit75b0804

File tree

3 files changed

+278
-452
lines changed

3 files changed

+278
-452
lines changed

‎tests/test_local.py

Lines changed: 0 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33

44
importpytest
55
importre
6-
importtempfile
76
importlogging
87

98
from ..testgresimportExecUtilException
10-
from ..testgresimportInvalidOperationException
119
from ..testgresimportLocalOperations
1210

1311
from .helpers.run_conditionsimportRunConditions
@@ -98,59 +96,6 @@ def test_listdir(self):
9896
assertfisnotNone
9997
asserttype(f)==str# noqa: E721
10098

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-
15499
deftest_read__unknown_file(self):
155100
"""
156101
Test LocalOperations::read with unknown file.
@@ -159,40 +104,6 @@ def test_read__unknown_file(self):
159104
withpytest.raises(FileNotFoundError,match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
160105
self.operations.read("/dummy")
161106

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-
196107
deftest_read_binary__spec__unk_file(self):
197108
"""
198109
Test LocalOperations::read_binary with unknown file.
@@ -234,70 +145,6 @@ def test_get_file_size__unk_file(self):
234145
withpytest.raises(FileNotFoundError,match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
235146
self.operations.get_file_size("/dummy")
236147

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-
301148
deftest_cwd(self):
302149
"""
303150
Test cwd.
@@ -314,71 +161,3 @@ def test_cwd(self):
314161

315162
# Comp result
316163
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