Skip to content

OsOperations::cwd() is corrected #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions testgres/operations/local_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
def environ(self, var_name):
return os.environ.get(var_name)

def cwd(self):
return os.getcwd()

def find_executable(self, executable):
return find_executable(executable)

Expand Down
7 changes: 1 addition & 6 deletions testgres/operations/os_ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getpass
import locale
import sys

try:
import psycopg2 as pglib # noqa: F401
Expand Down Expand Up @@ -39,11 +38,7 @@ def environ(self, var_name):
raise NotImplementedError()

def cwd(self):
if sys.platform == 'linux':
cmd = 'pwd'
elif sys.platform == 'win32':
cmd = 'cd'
return self.exec_command(cmd).decode().rstrip()
raise NotImplementedError()

def find_executable(self, executable):
raise NotImplementedError()
Expand Down
4 changes: 4 additions & 0 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def environ(self, var_name: str) -> str:
cmd = "echo ${}".format(var_name)
return self.exec_command(cmd, encoding=get_default_encoding()).strip()

def cwd(self):
cmd = 'pwd'
return self.exec_command(cmd, encoding=get_default_encoding()).rstrip()

def find_executable(self, executable):
search_paths = self.environ("PATH")
if not search_paths:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,20 @@ def test_isdir_false__file(self):
response = self.operations.isdir(name)

assert response is False

def test_cwd(self):
"""
Test cwd.
"""
v = self.operations.cwd()

assert v is not None
assert type(v) == str # noqa: E721

expectedValue = os.getcwd()
assert expectedValue is not None
assert type(expectedValue) == str # noqa: E721
assert expectedValue != "" # research

# Comp result
assert v == expectedValue
10 changes: 10 additions & 0 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,13 @@ def test_isdir_false__file(self):
response = self.operations.isdir(name)

assert response is False

def test_cwd(self):
"""
Test cwd.
"""
v = self.operations.cwd()

assert v is not None
assert type(v) == str # noqa: E721
assert v != ""