Skip to content

Commit 4493d69

Browse files
OsOperations::cwd() is corrected (#182)
* OsOperations::cwd() is corrected This patch fixes the following problems: - It does not work on Windows - It always returns LOCAL path
1 parent 737e0b4 commit 4493d69

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

testgres/operations/local_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
152152
def environ(self, var_name):
153153
return os.environ.get(var_name)
154154

155+
def cwd(self):
156+
return os.getcwd()
157+
155158
def find_executable(self, executable):
156159
return find_executable(executable)
157160

testgres/operations/os_ops.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import getpass
22
import locale
3-
import sys
43

54
try:
65
import psycopg2 as pglib # noqa: F401
@@ -39,11 +38,7 @@ def environ(self, var_name):
3938
raise NotImplementedError()
4039

4140
def cwd(self):
42-
if sys.platform == 'linux':
43-
cmd = 'pwd'
44-
elif sys.platform == 'win32':
45-
cmd = 'cd'
46-
return self.exec_command(cmd).decode().rstrip()
41+
raise NotImplementedError()
4742

4843
def find_executable(self, executable):
4944
raise NotImplementedError()

testgres/operations/remote_ops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ def environ(self, var_name: str) -> str:
138138
cmd = "echo ${}".format(var_name)
139139
return self.exec_command(cmd, encoding=get_default_encoding()).strip()
140140

141+
def cwd(self):
142+
cmd = 'pwd'
143+
return self.exec_command(cmd, encoding=get_default_encoding()).rstrip()
144+
141145
def find_executable(self, executable):
142146
search_paths = self.environ("PATH")
143147
if not search_paths:

tests/test_local.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,20 @@ def test_isdir_false__file(self):
256256
response = self.operations.isdir(name)
257257

258258
assert response is False
259+
260+
def test_cwd(self):
261+
"""
262+
Test cwd.
263+
"""
264+
v = self.operations.cwd()
265+
266+
assert v is not None
267+
assert type(v) == str # noqa: E721
268+
269+
expectedValue = os.getcwd()
270+
assert expectedValue is not None
271+
assert type(expectedValue) == str # noqa: E721
272+
assert expectedValue != "" # research
273+
274+
# Comp result
275+
assert v == expectedValue

tests/test_remote.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,13 @@ def test_isdir_false__file(self):
392392
response = self.operations.isdir(name)
393393

394394
assert response is False
395+
396+
def test_cwd(self):
397+
"""
398+
Test cwd.
399+
"""
400+
v = self.operations.cwd()
401+
402+
assert v is not None
403+
assert type(v) == str # noqa: E721
404+
assert v != ""

0 commit comments

Comments
 (0)