summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-08 08:07:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-08 08:07:38 +0000
commitf6a576f0ec04a9b2fa2982e2e9188d874bbd156c (patch)
tree2224798b59442d1e4f6124afdbba2aafa6984fc1 /test
parentReleasing debian version 1.26.1-3. (diff)
downloadmycli-f6a576f0ec04a9b2fa2982e2e9188d874bbd156c.tar.xz
mycli-f6a576f0ec04a9b2fa2982e2e9188d874bbd156c.zip
Merging upstream version 1.27.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test')
-rw-r--r--test/myclirc155
-rw-r--r--test/test_completion_refresher.py2
-rw-r--r--test/test_main.py49
-rw-r--r--test/test_naive_completion.py8
-rw-r--r--test/test_smart_completion_public_schema_only.py52
-rw-r--r--test/test_special_iocommands.py82
-rw-r--r--test/test_sqlexecute.py17
-rw-r--r--test/test_tabular_output.py4
8 files changed, 301 insertions, 68 deletions
diff --git a/test/myclirc b/test/myclirc
index 261bee6..0c1a7ad 100644
--- a/test/myclirc
+++ b/test/myclirc
@@ -1,12 +1,157 @@
# vi: ft=dosini
+[main]
-# This file is loaded after mycli/myclirc and should override only those
-# variables needed for testing.
-# To see what every variable does see mycli/myclirc
+# Enables context sensitive auto-completion. If this is disabled the all
+# possible completions will be listed.
+smart_completion = True
-[main]
+# Multi-line mode allows breaking up the sql statements into multiple lines. If
+# this is set to True, then the end of the statements must have a semi-colon.
+# If this is set to False then sql statements can't be split into multiple
+# lines. End of line (return) is considered as the end of the statement.
+multi_line = False
+
+# Destructive warning mode will alert you before executing a sql statement
+# that may cause harm to the database such as "drop table", "drop database"
+# or "shutdown".
+destructive_warning = True
+# log_file location.
log_file = ~/.mycli.test.log
+
+# Default log level. Possible values: "CRITICAL", "ERROR", "WARNING", "INFO"
+# and "DEBUG". "NONE" disables logging.
log_level = DEBUG
-prompt = '\t \u@\h:\d> '
+
+# Log every query and its results to a file. Enable this by uncommenting the
+# line below.
+# audit_log = ~/.mycli-audit.log
+
+# Timing of sql statements and table rendering.
+timing = True
+
+# Beep after long-running queries are completed; 0 to disable.
+beep_after_seconds = 0
+
+# Table format. Possible values: ascii, double, github,
+# psql, plain, simple, grid, fancy_grid, pipe, orgtbl, rst, mediawiki, html,
+# latex, latex_booktabs, textile, moinmoin, jira, vertical, tsv, csv.
+# Recommended: ascii
+table_format = ascii
+
+# Syntax coloring style. Possible values (many support the "-dark" suffix):
+# manni, igor, xcode, vim, autumn, vs, rrt, native, perldoc, borland, tango, emacs,
+# friendly, monokai, paraiso, colorful, murphy, bw, pastie, paraiso, trac, default,
+# fruity.
+# Screenshots at http://mycli.net/syntax
+# Can be further modified in [colors]
+syntax_style = default
+
+# Keybindings: Possible values: emacs, vi.
+# Emacs mode: Ctrl-A is home, Ctrl-E is end. All emacs keybindings are available in the REPL.
+# When Vi mode is enabled you can use modal editing features offered by Vi in the REPL.
+key_bindings = emacs
+
+# Enabling this option will show the suggestions in a wider menu. Thus more items are suggested.
+wider_completion_menu = False
+
+# MySQL prompt
+# \D - The full current date
+# \d - Database name
+# \h - Hostname of the server
+# \m - Minutes of the current time
+# \n - Newline
+# \P - AM/PM
+# \p - Port
+# \R - The current time, in 24-hour military time (0-23)
+# \r - The current time, standard 12-hour time (1-12)
+# \s - Seconds of the current time
+# \t - Product type (Percona, MySQL, MariaDB, TiDB)
+# \A - DSN alias name (from the [alias_dsn] section)
+# \u - Username
+# \x1b[...m - insert ANSI escape sequence
+prompt = "\t \u@\h:\d> "
+prompt_continuation = ->
+
+# Skip intro info on startup and outro info on exit
less_chatty = True
+
+# Use alias from --login-path instead of host name in prompt
+login_path_as_host = False
+
+# Cause result sets to be displayed vertically if they are too wide for the current window,
+# and using normal tabular format otherwise. (This applies to statements terminated by ; or \G.)
+auto_vertical_output = False
+
+# keyword casing preference. Possible values "lower", "upper", "auto"
+keyword_casing = auto
+
+# disabled pager on startup
+enable_pager = True
+
+# Custom colors for the completion menu, toolbar, etc.
+[colors]
+completion-menu.completion.current = "bg:#ffffff #000000"
+completion-menu.completion = "bg:#008888 #ffffff"
+completion-menu.meta.completion.current = "bg:#44aaaa #000000"
+completion-menu.meta.completion = "bg:#448888 #ffffff"
+completion-menu.multi-column-meta = "bg:#aaffff #000000"
+scrollbar.arrow = "bg:#003333"
+scrollbar = "bg:#00aaaa"
+selected = "#ffffff bg:#6666aa"
+search = "#ffffff bg:#4444aa"
+search.current = "#ffffff bg:#44aa44"
+bottom-toolbar = "bg:#222222 #aaaaaa"
+bottom-toolbar.off = "bg:#222222 #888888"
+bottom-toolbar.on = "bg:#222222 #ffffff"
+search-toolbar = noinherit bold
+search-toolbar.text = nobold
+system-toolbar = noinherit bold
+arg-toolbar = noinherit bold
+arg-toolbar.text = nobold
+bottom-toolbar.transaction.valid = "bg:#222222 #00ff5f bold"
+bottom-toolbar.transaction.failed = "bg:#222222 #ff005f bold"
+
+# style classes for colored table output
+output.header = "#00ff5f bold"
+output.odd-row = ""
+output.even-row = ""
+output.null = "#808080"
+
+# SQL syntax highlighting overrides
+# sql.comment = 'italic #408080'
+# sql.comment.multi-line = ''
+# sql.comment.single-line = ''
+# sql.comment.optimizer-hint = ''
+# sql.escape = 'border:#FF0000'
+# sql.keyword = 'bold #008000'
+# sql.datatype = 'nobold #B00040'
+# sql.literal = ''
+# sql.literal.date = ''
+# sql.symbol = ''
+# sql.quoted-schema-object = ''
+# sql.quoted-schema-object.escape = ''
+# sql.constant = '#880000'
+# sql.function = '#0000FF'
+# sql.variable = '#19177C'
+# sql.number = '#666666'
+# sql.number.binary = ''
+# sql.number.float = ''
+# sql.number.hex = ''
+# sql.number.integer = ''
+# sql.operator = '#666666'
+# sql.punctuation = ''
+# sql.string = '#BA2121'
+# sql.string.double-quouted = ''
+# sql.string.escape = 'bold #BB6622'
+# sql.string.single-quoted = ''
+# sql.whitespace = ''
+
+# Favorite queries.
+[favorite_queries]
+check = 'select "✔"'
+
+# Use the -d option to reference a DSN.
+# Special characters in passwords and other strings can be escaped with URL encoding.
+[alias_dsn]
+# example_dsn = mysql://[user[:password]@][host][:port][/dbname]
diff --git a/test/test_completion_refresher.py b/test/test_completion_refresher.py
index cdc2fb5..31359cf 100644
--- a/test/test_completion_refresher.py
+++ b/test/test_completion_refresher.py
@@ -19,7 +19,7 @@ def test_ctor(refresher):
assert len(refresher.refreshers) > 0
actual_handlers = list(refresher.refreshers.keys())
expected_handlers = ['databases', 'schemata', 'tables', 'users', 'functions',
- 'special_commands', 'show_commands']
+ 'special_commands', 'show_commands', 'keywords']
assert expected_handlers == actual_handlers
diff --git a/test/test_main.py b/test/test_main.py
index 64cba0a..589d6cd 100644
--- a/test/test_main.py
+++ b/test/test_main.py
@@ -254,23 +254,21 @@ def test_conditional_pager(monkeypatch):
SPECIAL_COMMANDS['pager'].handler('')
-def test_reserved_space_is_integer():
+def test_reserved_space_is_integer(monkeypatch):
"""Make sure that reserved space is returned as an integer."""
def stub_terminal_size():
return (5, 5)
- old_func = shutil.get_terminal_size
-
- shutil.get_terminal_size = stub_terminal_size
- mycli = MyCli()
- assert isinstance(mycli.get_reserved_space(), int)
-
- shutil.get_terminal_size = old_func
+ with monkeypatch.context() as m:
+ m.setattr(shutil, 'get_terminal_size', stub_terminal_size)
+ mycli = MyCli()
+ assert isinstance(mycli.get_reserved_space(), int)
def test_list_dsn():
runner = CliRunner()
- with NamedTemporaryFile(mode="w") as myclirc:
+ # keep Windows from locking the file with delete=False
+ with NamedTemporaryFile(mode="w",delete=False) as myclirc:
myclirc.write(dedent("""\
[alias_dsn]
test = mysql://test/test
@@ -281,6 +279,15 @@ def test_list_dsn():
assert result.output == "test\n"
result = runner.invoke(cli, args=args + ['--verbose'])
assert result.output == "test : mysql://test/test\n"
+
+ # delete=False means we should try to clean up
+ try:
+ if os.path.exists(myclirc.name):
+ os.remove(myclirc.name)
+ except Exception as e:
+ print(f"An error occurred while attempting to delete the file: {e}")
+
+
def test_prettify_statement():
@@ -299,7 +306,8 @@ def test_unprettify_statement():
def test_list_ssh_config():
runner = CliRunner()
- with NamedTemporaryFile(mode="w") as ssh_config:
+ # keep Windows from locking the file with delete=False
+ with NamedTemporaryFile(mode="w",delete=False) as ssh_config:
ssh_config.write(dedent("""\
Host test
Hostname test.example.com
@@ -313,6 +321,13 @@ def test_list_ssh_config():
assert "test\n" in result.output
result = runner.invoke(cli, args=args + ['--verbose'])
assert "test : test.example.com\n" in result.output
+
+ # delete=False means we should try to clean up
+ try:
+ if os.path.exists(ssh_config.name):
+ os.remove(ssh_config.name)
+ except Exception as e:
+ print(f"An error occurred while attempting to delete the file: {e}")
def test_dsn(monkeypatch):
@@ -466,7 +481,8 @@ def test_ssh_config(monkeypatch):
runner = CliRunner()
# Setup temporary configuration
- with NamedTemporaryFile(mode="w") as ssh_config:
+ # keep Windows from locking the file with delete=False
+ with NamedTemporaryFile(mode="w",delete=False) as ssh_config:
ssh_config.write(dedent("""\
Host test
Hostname test.example.com
@@ -489,8 +505,8 @@ def test_ssh_config(monkeypatch):
MockMyCli.connect_args["ssh_user"] == "joe" and \
MockMyCli.connect_args["ssh_host"] == "test.example.com" and \
MockMyCli.connect_args["ssh_port"] == 22222 and \
- MockMyCli.connect_args["ssh_key_filename"] == os.getenv(
- "HOME") + "/.ssh/gateway"
+ MockMyCli.connect_args["ssh_key_filename"] == os.path.expanduser(
+ "~") + "/.ssh/gateway"
# When a user supplies a ssh config host as argument to mycli,
# and used command line arguments, use the command line
@@ -512,6 +528,13 @@ def test_ssh_config(monkeypatch):
MockMyCli.connect_args["ssh_host"] == "arg_host" and \
MockMyCli.connect_args["ssh_port"] == 3 and \
MockMyCli.connect_args["ssh_key_filename"] == "/path/to/key"
+
+ # delete=False means we should try to clean up
+ try:
+ if os.path.exists(ssh_config.name):
+ os.remove(ssh_config.name)
+ except Exception as e:
+ print(f"An error occurred while attempting to delete the file: {e}")
@dbtest
diff --git a/test/test_naive_completion.py b/test/test_naive_completion.py
index 32b2abd..0bc3bf8 100644
--- a/test/test_naive_completion.py
+++ b/test/test_naive_completion.py
@@ -21,7 +21,7 @@ def test_empty_string_completion(completer, complete_event):
result = list(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert result == list(map(Completion, sorted(completer.all_completions)))
+ assert result == list(map(Completion, completer.all_completions))
def test_select_keyword_completion(completer, complete_event):
@@ -39,9 +39,7 @@ def test_function_name_completion(completer, complete_event):
result = list(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert result == list([
- Completion(text='MASTER', start_position=-2),
- Completion(text='MAX', start_position=-2)])
+ assert sorted(x.text for x in result) == ["MASTER", "MAX"]
def test_column_name_completion(completer, complete_event):
@@ -50,7 +48,7 @@ def test_column_name_completion(completer, complete_event):
result = list(completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert result == list(map(Completion, sorted(completer.all_completions)))
+ assert result == list(map(Completion, completer.all_completions))
def test_special_name_completion(completer, complete_event):
diff --git a/test/test_smart_completion_public_schema_only.py b/test/test_smart_completion_public_schema_only.py
index e7d460a..b60e67c 100644
--- a/test/test_smart_completion_public_schema_only.py
+++ b/test/test_smart_completion_public_schema_only.py
@@ -55,8 +55,8 @@ def test_empty_string_completion(completer, complete_event):
completer.get_completions(
Document(text=text, cursor_position=position),
complete_event))
- assert list(map(Completion, sorted(completer.keywords) +
- sorted(completer.special_commands))) == result
+ assert list(map(Completion, completer.keywords +
+ completer.special_commands)) == result
def test_select_keyword_completion(completer, complete_event):
@@ -74,10 +74,10 @@ def test_table_completion(completer, complete_event):
result = completer.get_completions(
Document(text=text, cursor_position=position), complete_event)
assert list(result) == list([
- Completion(text='`réveillé`', start_position=0),
- Completion(text='`select`', start_position=0),
- Completion(text='orders', start_position=0),
Completion(text='users', start_position=0),
+ Completion(text='orders', start_position=0),
+ Completion(text='`select`', start_position=0),
+ Completion(text='`réveillé`', start_position=0),
])
@@ -106,9 +106,9 @@ def test_suggested_column_names(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0),
] +
list(map(Completion, completer.functions)) +
@@ -132,9 +132,9 @@ def test_suggested_column_names_in_function(completer, complete_event):
complete_event)
assert list(result) == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0)])
@@ -153,9 +153,9 @@ def test_suggested_column_names_with_table_dot(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0)])
@@ -174,9 +174,9 @@ def test_suggested_column_names_with_alias(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0)])
@@ -196,9 +196,9 @@ def test_suggested_multiple_column_names(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0)] +
list(map(Completion, completer.functions)) +
[Completion(text='u', start_position=0)] +
@@ -221,9 +221,9 @@ def test_suggested_multiple_column_names_with_alias(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0)])
@@ -243,9 +243,9 @@ def test_suggested_multiple_column_names_with_dot(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
+ Completion(text='id', start_position=0),
Completion(text='email', start_position=0),
Completion(text='first_name', start_position=0),
- Completion(text='id', start_position=0),
Completion(text='last_name', start_position=0)])
@@ -256,8 +256,9 @@ def test_suggested_aliases_after_on(completer, complete_event):
Document(text=text, cursor_position=position),
complete_event))
assert result == list([
+ Completion(text='u', start_position=0),
Completion(text='o', start_position=0),
- Completion(text='u', start_position=0)])
+ ])
def test_suggested_aliases_after_on_right_side(completer, complete_event):
@@ -268,8 +269,9 @@ def test_suggested_aliases_after_on_right_side(completer, complete_event):
Document(text=text, cursor_position=position),
complete_event))
assert result == list([
+ Completion(text='u', start_position=0),
Completion(text='o', start_position=0),
- Completion(text='u', start_position=0)])
+ ])
def test_suggested_tables_after_on(completer, complete_event):
@@ -279,8 +281,9 @@ def test_suggested_tables_after_on(completer, complete_event):
Document(text=text, cursor_position=position),
complete_event))
assert result == list([
+ Completion(text='users', start_position=0),
Completion(text='orders', start_position=0),
- Completion(text='users', start_position=0)])
+ ])
def test_suggested_tables_after_on_right_side(completer, complete_event):
@@ -291,8 +294,9 @@ def test_suggested_tables_after_on_right_side(completer, complete_event):
Document(text=text, cursor_position=position),
complete_event))
assert result == list([
+ Completion(text='users', start_position=0),
Completion(text='orders', start_position=0),
- Completion(text='users', start_position=0)])
+ ])
def test_table_names_after_from(completer, complete_event):
@@ -302,10 +306,10 @@ def test_table_names_after_from(completer, complete_event):
Document(text=text, cursor_position=position),
complete_event))
assert result == list([
- Completion(text='`réveillé`', start_position=0),
- Completion(text='`select`', start_position=0),
- Completion(text='orders', start_position=0),
Completion(text='users', start_position=0),
+ Completion(text='orders', start_position=0),
+ Completion(text='`select`', start_position=0),
+ Completion(text='`réveillé`', start_position=0),
])
@@ -317,12 +321,12 @@ def test_auto_escaped_col_names(completer, complete_event):
complete_event))
assert result == [
Completion(text='*', start_position=0),
- Completion(text='`ABC`', start_position=0),
- Completion(text='`insert`', start_position=0),
Completion(text='id', start_position=0),
+ Completion(text='`insert`', start_position=0),
+ Completion(text='`ABC`', start_position=0),
] + \
list(map(Completion, completer.functions)) + \
- [Completion(text='`select`', start_position=0)] + \
+ [Completion(text='select', start_position=0)] + \
list(map(Completion, completer.keywords))
@@ -334,9 +338,9 @@ def test_un_escaped_table_names(completer, complete_event):
complete_event))
assert result == list([
Completion(text='*', start_position=0),
- Completion(text='`ABC`', start_position=0),
- Completion(text='`insert`', start_position=0),
Completion(text='id', start_position=0),
+ Completion(text='`insert`', start_position=0),
+ Completion(text='`ABC`', start_position=0),
] +
list(map(Completion, completer.functions)) +
[Completion(text='réveillé', start_position=0)] +
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`:
diff --git a/test/test_sqlexecute.py b/test/test_sqlexecute.py
index 38ca5ef..ca186bc 100644
--- a/test/test_sqlexecute.py
+++ b/test/test_sqlexecute.py
@@ -117,6 +117,7 @@ def test_multiple_queries_same_line_syntaxerror(executor):
@dbtest
+@pytest.mark.skipif(os.name == "nt", reason="Bug: fails on Windows, needs fixing, singleton of FQ not working right")
def test_favorite_query(executor):
set_expanded_output(False)
run(executor, "create table test(a text)")
@@ -136,6 +137,7 @@ def test_favorite_query(executor):
@dbtest
+@pytest.mark.skipif(os.name == "nt", reason="Bug: fails on Windows, needs fixing, singleton of FQ not working right")
def test_favorite_query_multiple_statement(executor):
set_expanded_output(False)
run(executor, "create table test(a text)")
@@ -159,6 +161,7 @@ def test_favorite_query_multiple_statement(executor):
@dbtest
+@pytest.mark.skipif(os.name == "nt", reason="Bug: fails on Windows, needs fixing, singleton of FQ not working right")
def test_favorite_query_expanded_output(executor):
set_expanded_output(False)
run(executor, '''create table test(a text)''')
@@ -195,16 +198,21 @@ def test_cd_command_without_a_folder_name(executor):
@dbtest
def test_system_command_not_found(executor):
results = run(executor, 'system xyz')
- assert_result_equal(results, status='OSError: No such file or directory',
- assert_contains=True)
+ if os.name=='nt':
+ assert_result_equal(results, status='OSError: The system cannot find the file specified',
+ assert_contains=True)
+ else:
+ assert_result_equal(results, status='OSError: No such file or directory',
+ assert_contains=True)
@dbtest
def test_system_command_output(executor):
+ eol = os.linesep
test_dir = os.path.abspath(os.path.dirname(__file__))
test_file_path = os.path.join(test_dir, 'test.txt')
results = run(executor, 'system cat {0}'.format(test_file_path))
- assert_result_equal(results, status='mycli rocks!\n')
+ assert_result_equal(results, status=f'mycli rocks!{eol}')
@dbtest
@@ -276,7 +284,8 @@ def test_multiple_results(executor):
@pytest.mark.parametrize(
'version_string, species, parsed_version_string, version',
(
- ('5.7.25-TiDB-v6.1.0','TiDB', '5.7.25', 50725),
+ ('5.7.25-TiDB-v6.1.0','TiDB', '6.1.0', 60100),
+ ('8.0.11-TiDB-v7.2.0-alpha-69-g96e9e68daa', 'TiDB', '7.2.0', 70200),
('5.7.32-35', 'Percona', '5.7.32', 50732),
('5.7.32-0ubuntu0.18.04.1', 'MySQL', '5.7.32', 50732),
('10.5.8-MariaDB-1:10.5.8+maria~focal', 'MariaDB', '10.5.8', 100508),
diff --git a/test/test_tabular_output.py b/test/test_tabular_output.py
index c20c7de..bdc1dbf 100644
--- a/test/test_tabular_output.py
+++ b/test/test_tabular_output.py
@@ -102,7 +102,7 @@ def test_sql_output(mycli):
mycli.formatter.query = "SELECT * FROM `table`"
output = mycli.format_output(None, FakeCursor(), headers)
assert "\n".join(output) == dedent('''\
- INSERT INTO `table` (`letters`, `number`, `optional`, `float`, `binary`) VALUES
+ INSERT INTO table (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
;''')
@@ -112,7 +112,7 @@ def test_sql_output(mycli):
mycli.formatter.query = "SELECT * FROM `database`.`table`"
output = mycli.format_output(None, FakeCursor(), headers)
assert "\n".join(output) == dedent('''\
- INSERT INTO `database`.`table` (`letters`, `number`, `optional`, `float`, `binary`) VALUES
+ INSERT INTO database.table (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
;''')