summaryrefslogtreecommitdiffstats
path: root/test/test_special_iocommands.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 03:05:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 03:05:51 +0000
commit50e35b00904a3de9ae1d4e693a8484b676f410b0 (patch)
treea6cc98082c0141a191e4c798fc57d43b83456c41 /test/test_special_iocommands.py
parentReleasing progress-linux version 1.27.0-1~progress7.99u1. (diff)
downloadmycli-50e35b00904a3de9ae1d4e693a8484b676f410b0.tar.xz
mycli-50e35b00904a3de9ae1d4e693a8484b676f410b0.zip
Merging upstream version 1.27.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_special_iocommands.py')
-rw-r--r--test/test_special_iocommands.py82
1 files changed, 68 insertions, 14 deletions
diff --git a/test/test_special_iocommands.py b/test/test_special_iocommands.py
index 8b6be33..d0ca45f 100644
--- a/test/test_special_iocommands.py
+++ b/test/test_special_iocommands.py
@@ -50,25 +50,49 @@ def test_editor_command():
os.environ['EDITOR'] = 'true'
os.environ['VISUAL'] = 'true'
- mycli.packages.special.open_external_editor(sql=r'select 1') == "select 1"
+ # Set the editor to Notepad on Windows
+ if os.name != 'nt':
+ mycli.packages.special.open_external_editor(sql=r'select 1') == "select 1"
+ else:
+ pytest.skip('Skipping on Windows platform.')
+
def test_tee_command():
mycli.packages.special.write_tee(u"hello world") # write without file set
- with tempfile.NamedTemporaryFile() as f:
+ # keep Windows from locking the file with delete=False
+ with tempfile.NamedTemporaryFile(delete=False) as f:
mycli.packages.special.execute(None, u"tee " + f.name)
mycli.packages.special.write_tee(u"hello world")
- assert f.read() == b"hello world\n"
+ if os.name=='nt':
+ assert f.read() == b"hello world\r\n"
+ else:
+ assert f.read() == b"hello world\n"
mycli.packages.special.execute(None, u"tee -o " + f.name)
mycli.packages.special.write_tee(u"hello world")
f.seek(0)
- assert f.read() == b"hello world\n"
+ if os.name=='nt':
+ assert f.read() == b"hello world\r\n"
+ else:
+ assert f.read() == b"hello world\n"
mycli.packages.special.execute(None, u"notee")
mycli.packages.special.write_tee(u"hello world")
f.seek(0)
- assert f.read() == b"hello world\n"
+ if os.name=='nt':
+ assert f.read() == b"hello world\r\n"
+ else:
+ assert f.read() == b"hello world\n"
+
+ # remove temp file
+ # delete=False means we should try to clean up
+ try:
+ if os.path.exists(f.name):
+ os.remove(f.name)
+ except Exception as e:
+ print(f"An error occurred while attempting to delete the file: {e}")
+
def test_tee_command_error():
@@ -82,6 +106,8 @@ def test_tee_command_error():
@dbtest
+
+@pytest.mark.skipif(os.name == "nt", reason="Bug: fails on Windows, needs fixing, singleton of FQ not working right")
def test_favorite_query():
with db_connection().cursor() as cur:
query = u'select "✔"'
@@ -98,16 +124,29 @@ def test_once_command():
mycli.packages.special.execute(None, u"\\once /proc/access-denied")
mycli.packages.special.write_once(u"hello world") # write without file set
- with tempfile.NamedTemporaryFile() as f:
+ # keep Windows from locking the file with delete=False
+ with tempfile.NamedTemporaryFile(delete=False) as f:
mycli.packages.special.execute(None, u"\\once " + f.name)
mycli.packages.special.write_once(u"hello world")
- assert f.read() == b"hello world\n"
+ if os.name=='nt':
+ assert f.read() == b"hello world\r\n"
+ else:
+ assert f.read() == b"hello world\n"
mycli.packages.special.execute(None, u"\\once -o " + f.name)
mycli.packages.special.write_once(u"hello world line 1")
mycli.packages.special.write_once(u"hello world line 2")
f.seek(0)
- assert f.read() == b"hello world line 1\nhello world line 2\n"
+ if os.name=='nt':
+ assert f.read() == b"hello world line 1\r\nhello world line 2\r\n"
+ else:
+ assert f.read() == b"hello world line 1\nhello world line 2\n"
+ # delete=False means we should try to clean up
+ try:
+ if os.path.exists(f.name):
+ os.remove(f.name)
+ except Exception as e:
+ print(f"An error occurred while attempting to delete the file: {e}")
def test_pipe_once_command():
@@ -118,9 +157,14 @@ def test_pipe_once_command():
mycli.packages.special.execute(
None, u"\\pipe_once /proc/access-denied")
- mycli.packages.special.execute(None, u"\\pipe_once wc")
- mycli.packages.special.write_once(u"hello world")
- mycli.packages.special.unset_pipe_once_if_written()
+ if os.name == 'nt':
+ mycli.packages.special.execute(None, u'\\pipe_once python -c "import sys; print(len(sys.stdin.read().strip()))"')
+ mycli.packages.special.write_once(u"hello world")
+ mycli.packages.special.unset_pipe_once_if_written()
+ else:
+ mycli.packages.special.execute(None, u"\\pipe_once wc")
+ mycli.packages.special.write_once(u"hello world")
+ mycli.packages.special.unset_pipe_once_if_written()
# how to assert on wc output?
@@ -128,12 +172,21 @@ def test_parseargfile():
"""Test that parseargfile expands the user directory."""
expected = {'file': os.path.join(os.path.expanduser('~'), 'filename'),
'mode': 'a'}
- assert expected == mycli.packages.special.iocommands.parseargfile(
- '~/filename')
+
+ if os.name=='nt':
+ assert expected == mycli.packages.special.iocommands.parseargfile(
+ '~\\filename')
+ else:
+ assert expected == mycli.packages.special.iocommands.parseargfile(
+ '~/filename')
expected = {'file': os.path.join(os.path.expanduser('~'), 'filename'),
'mode': 'w'}
- assert expected == mycli.packages.special.iocommands.parseargfile(
+ if os.name=='nt':
+ assert expected == mycli.packages.special.iocommands.parseargfile(
+ '-o ~\\filename')
+ else:
+ assert expected == mycli.packages.special.iocommands.parseargfile(
'-o ~/filename')
@@ -162,6 +215,7 @@ def test_watch_query_iteration():
@dbtest
+@pytest.mark.skipif(os.name == "nt", reason="Bug: Win handles this differently. May need to refactor watch_query to work for Win")
def test_watch_query_full():
"""Test that `watch_query`: