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

Commitedd64db

Browse files
OsOperations::get_tempdir() is added (#254)
Signature: def get_tempdir(self) -> str
1 parenta0a8506 commitedd64db

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

‎testgres/operations/local_ops.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,10 @@ def is_port_free(self, number: int) -> bool:
528528
returnTrue
529529
exceptOSError:
530530
returnFalse
531+
532+
defget_tempdir(self)->str:
533+
r=tempfile.gettempdir()
534+
assertrisnotNone
535+
asserttype(r)==str# noqa: E721
536+
assertos.path.exists(r)
537+
returnr

‎testgres/operations/os_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,6 @@ def get_process_children(self, pid):
130130
defis_port_free(self,number:int):
131131
asserttype(number)==int# noqa: E721
132132
raiseNotImplementedError()
133+
134+
defget_tempdir(self)->str:
135+
raiseNotImplementedError()

‎testgres/operations/remote_ops.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,34 @@ def is_port_free(self, number: int) -> bool:
659659
out=output
660660
)
661661

662+
defget_tempdir(self)->str:
663+
command= ["mktemp","-u","-d"]
664+
665+
exec_exitcode,exec_output,exec_error=self.exec_command(
666+
command,
667+
verbose=True,
668+
encoding=get_default_encoding(),
669+
ignore_errors=True
670+
)
671+
672+
asserttype(exec_exitcode)==int# noqa: E721
673+
asserttype(exec_output)==str# noqa: E721
674+
asserttype(exec_error)==str# noqa: E721
675+
676+
ifexec_exitcode!=0:
677+
RaiseError.CommandExecutionError(
678+
cmd=command,
679+
exit_code=exec_exitcode,
680+
message="Could not detect a temporary directory.",
681+
error=exec_error,
682+
out=exec_output)
683+
684+
temp_subdir=exec_output.strip()
685+
asserttype(temp_subdir)==str# noqa: E721
686+
temp_dir=os.path.dirname(temp_subdir)
687+
asserttype(temp_dir)==str# noqa: E721
688+
returntemp_dir
689+
662690
@staticmethod
663691
def_is_port_free__process_0(error:str)->bool:
664692
asserttype(error)==str# noqa: E721

‎tests/test_os_ops_common.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,39 @@ def LOCAL_server(s: socket.socket):
817817
ifok_count==0:
818818
raiseRuntimeError("No one free port was found.")
819819

820+
deftest_get_tmpdir(self,os_ops:OsOperations):
821+
assertisinstance(os_ops,OsOperations)
822+
823+
dir=os_ops.get_tempdir()
824+
asserttype(dir)==str# noqa: E721
825+
assertos_ops.path_exists(dir)
826+
assertos.path.exists(dir)
827+
828+
file_path=os.path.join(dir,"testgres--"+uuid.uuid4().hex+".tmp")
829+
830+
os_ops.write(file_path,"1234",binary=False)
831+
832+
assertos_ops.path_exists(file_path)
833+
assertos.path.exists(file_path)
834+
835+
d=os_ops.read(file_path,binary=False)
836+
837+
assertd=="1234"
838+
839+
os_ops.remove_file(file_path)
840+
841+
assertnotos_ops.path_exists(file_path)
842+
assertnotos.path.exists(file_path)
843+
844+
deftest_get_tmpdir__compare_with_py_info(self,os_ops:OsOperations):
845+
assertisinstance(os_ops,OsOperations)
846+
847+
actual_dir=os_ops.get_tempdir()
848+
assertactual_dirisnotNone
849+
asserttype(actual_dir)==str# noqa: E721
850+
expected_dir=str(tempfile.tempdir)
851+
assertactual_dir==expected_dir
852+
820853
classtagData_OS_OPS__NUMS:
821854
os_ops_descr:OsOpsDescr
822855
nums:int

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp