From 140bb351328f463595c6a9d937450c41530263fd Mon Sep 17 00:00:00 2001 From: Dmitriy Gertsog Date: Wed, 25 Sep 2024 14:26:52 +0300 Subject: [PATCH] test: update test_connect to use stop_app Wrap call `start_app` & `stop_app` in try/finally blocks. Modified code was auto reformatted, also. Closes #956 --- test/integration/connect/test_connect.py | 3582 ++++++++++++---------- 1 file changed, 1980 insertions(+), 1602 deletions(-) diff --git a/test/integration/connect/test_connect.py b/test/integration/connect/test_connect.py index 2b2b1f178..24e139a49 100644 --- a/test/integration/connect/test_connect.py +++ b/test/integration/connect/test_connect.py @@ -59,8 +59,8 @@ def start_app(tt_cmd, tmpdir_with_cfg, app_name, start_binary_port=False): def stop_app(tt_cmd, tmpdir, app_name): - stop_cmd = [tt_cmd, "stop", app_name] - stop_rc, stop_out = run_command_and_get_output(stop_cmd, cwd=tmpdir) + stop_cmd = [tt_cmd, "stop", "-y", app_name] + run_command_and_get_output(stop_cmd, cwd=tmpdir) def try_execute_on_instance(tt_cmd, tmpdir, instance, @@ -227,13 +227,6 @@ def test_connect_and_get_commands_outputs(tt_cmd, tmpdir_with_cfg): # Copy test data into temporary directory. copy_data(tmpdir, [test_app_path, empty_file_path]) - # Start an instance. - start_app(tt_cmd, tmpdir, "test_app") - - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" - commands = {} help_output = """ To get help, see the Tarantool manual at https://tarantool.io/en/doc/ @@ -309,7 +302,13 @@ def test_connect_and_get_commands_outputs(tt_cmd, tmpdir_with_cfg): commands["\\quit"] = " • Quit from the console \n" commands["\\q"] = " • Quit from the console \n" + # Start an instance. + start_app(tt_cmd, tmpdir, "test_app") try: + # Check for start. + file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) + assert file != "" + for key, value in commands.items(): ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", stdin=key) print(output) @@ -419,37 +418,43 @@ def test_connect_to_localhost_app(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" - - # Connect to a wrong instance. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:6666", empty_file) - assert not ret - assert re.search(r" ⨯ unable to establish connection", output) + # Connect to a wrong instance. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:6666", empty_file + ) + assert not ret + assert re.search(r" ⨯ unable to establish connection", output) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute a script. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file) - assert ret - # Execute stdout. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="return ...", - args=["-f-", "Hello", "World"]) - assert ret - assert output == "---\n- Hello\n- World\n...\n\n" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute a script. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file) + assert ret + # Execute stdout. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="return ...", + args=["-f-", "Hello", "World"], + ) + assert ret + assert output == "---\n- Hello\n- World\n...\n\n" - # Execute stdout without args. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="2+2") - assert ret - assert output == "---\n- 4\n...\n\n" + # Execute stdout without args. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, stdin="2+2") + assert ret + assert output == "---\n- 4\n...\n\n" - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_connect_to_ssl_app(tt_cmd, tmpdir_with_cfg): @@ -468,28 +473,31 @@ def test_connect_to_ssl_app(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_ssl_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_ssl_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_ssl_app'), 'ready', []) - assert file != "" - - server = "localhost:3013" - # Connect without SSL options. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, server, empty_file) - assert not ret - assert re.search(r" ⨯ unable to establish connection", output) + server = "localhost:3013" + # Connect without SSL options. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, server, empty_file) + assert not ret + assert re.search(r" ⨯ unable to establish connection", output) - # Connect to the instance. - opts = { - "--sslkeyfile": "test_ssl_app/localhost.key", - "--sslcertfile": "test_ssl_app/localhost.crt", - "--sslcafile": "test_ssl_app/ca.crt", - } - ret, output = try_execute_on_instance(tt_cmd, tmpdir, server, empty_file, opts=opts) - assert ret + # Connect to the instance. + opts = { + "--sslkeyfile": "test_ssl_app/localhost.key", + "--sslcertfile": "test_ssl_app/localhost.crt", + "--sslcafile": "test_ssl_app/ca.crt", + } + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, server, empty_file, opts=opts + ) + assert ret - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_ssl_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_ssl_app") def test_connect_to_localhost_app_credentials(tt_cmd, tmpdir_with_cfg): @@ -504,79 +512,95 @@ def test_connect_to_localhost_app_credentials(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect with a wrong credentials. + opts = {"-u": "test", "-p": "wrong_password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts + ) + assert not ret + assert re.search(r" ⨯ unable to establish connection", output) + + # Connect with a wrong credentials via URL. + uri = "test:wrong_password@localhost:3013" + ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file) + assert not ret + assert re.search(r" ⨯ unable to establish connection", output) + + # Connect with a wrong credentials via environment variables. + env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, env=env + ) + assert not ret + assert re.search(r" ⨯ unable to establish connection", output) + + # Connect with a valid credentials. + opts = {"-u": "test", "-p": "password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts + ) + assert ret + + # Connect with a valid credentials via URL. + uri = "test:password@localhost:3013" + ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file) + assert ret + + # Connect with a valid credentials via environment variables. + env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, env=env + ) + assert ret + + # Connect with a valid credentials and wrong environment variables. + env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} + opts = {"-u": "test", "-p": "password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts, env=env + ) + assert ret + + # Connect with a valid credentials via URL and wrong environment variables. + env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} + uri = "test:password@localhost:3013" + ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file, env=env) + assert ret + + # Connect with a valid mixes of credentials and environment variables. + env = {"TT_CLI_PASSWORD": "password"} + opts = {"-u": "test"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts, env=env + ) + assert ret + + env = {"TT_CLI_USERNAME": "test"} + opts = {"-p": "password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts, env=env + ) + assert ret + + # Connect with a valid credentials via flags and via URL. + opts = {"-u": "test", "-p": "password"} + uri = "test:password@localhost:3013" + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, empty_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ username and password are specified with flags and a URI", output + ) - # Connect with a wrong credentials. - opts = {"-u": "test", "-p": "wrong_password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts) - assert not ret - assert re.search(r" ⨯ unable to establish connection", output) - - # Connect with a wrong credentials via URL. - uri = "test:wrong_password@localhost:3013" - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file) - assert not ret - assert re.search(r" ⨯ unable to establish connection", output) - - # Connect with a wrong credentials via environment variables. - env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", empty_file, env=env) - assert not ret - assert re.search(r" ⨯ unable to establish connection", output) - - # Connect with a valid credentials. - opts = {"-u": "test", "-p": "password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", empty_file, opts=opts) - assert ret - - # Connect with a valid credentials via URL. - uri = "test:password@localhost:3013" - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file) - assert ret - - # Connect with a valid credentials via environment variables. - env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", empty_file, env=env) - assert ret - - # Connect with a valid credentials and wrong environment variables. - env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} - opts = {"-u": "test", "-p": "password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", - empty_file, opts=opts, env=env) - assert ret - - # Connect with a valid credentials via URL and wrong environment variables. - env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} - uri = "test:password@localhost:3013" - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file, env=env) - assert ret - - # Connect with a valid mixes of credentials and environment variables. - env = {"TT_CLI_PASSWORD": "password"} - opts = {"-u": "test"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", - empty_file, opts=opts, env=env) - assert ret - - env = {"TT_CLI_USERNAME": "test"} - opts = {"-p": "password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "localhost:3013", - empty_file, opts=opts, env=env) - assert ret - - # Connect with a valid credentials via flags and via URL. - opts = {"-u": "test", "-p": "password"} - uri = "test:password@localhost:3013" - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, empty_file, opts=opts) - assert not ret - assert re.search(r" ⨯ username and password are specified with flags and a URI", output) - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_connect_to_single_instance_app(tt_cmd, tmpdir_with_cfg): @@ -591,31 +615,39 @@ def test_connect_to_single_instance_app(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file( + os.path.join(tmpdir, "test_app", run_path, "test_app"), control_socket, [] + ) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, "test_app", run_path, "test_app"), - control_socket, []) - assert file != "" - - # Connect to a wrong instance. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "any_app", empty_file) - assert not ret - assert re.search(r" ⨯ can\'t collect instance information for any_app", output) + # Connect to a wrong instance. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, "any_app", empty_file) + assert not ret + assert re.search( + r" ⨯ can\'t collect instance information for any_app", output + ) - # Connect to the instance and execute a script. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "test_app", empty_file) - assert ret + # Connect to the instance and execute a script. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, "test_app", empty_file) + assert ret - # Connect to the instance and execute stdout. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "test_app", - stdin="return ...", - args=["-f-", "Hello", "World"]) - print(output) - assert ret - assert output == "---\n- Hello\n- World\n...\n\n" + # Connect to the instance and execute stdout. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + "test_app", + stdin="return ...", + args=["-f-", "Hello", "World"], + ) + print(output) + assert ret + assert output == "---\n- Hello\n- World\n...\n\n" - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_connect_to_single_instance_app_credentials(tt_cmd, tmpdir_with_cfg): @@ -630,33 +662,47 @@ def test_connect_to_single_instance_app_credentials(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file( + os.path.join(tmpdir, "test_app", run_path, "test_app"), control_socket, [] + ) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, "test_app", run_path, "test_app"), - control_socket, []) - assert file != "" - - # Connect with a wrong credentials. - opts = {"-u": "test", "-p": "wrong_password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "test_app", empty_file, opts=opts) - assert not ret - assert re.search(r" ⨯ username and password are not supported with a" + - " connection via a control socket", output) + # Connect with a wrong credentials. + opts = {"-u": "test", "-p": "wrong_password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "test_app", empty_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ username and password are not supported with a" + + " connection via a control socket", + output, + ) - # Connect with a valid credentials. - opts = {"-u": "test", "-p": "password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "test_app", empty_file, opts=opts) - assert not ret - assert re.search(r" ⨯ username and password are not supported with a" + - " connection via a control socket", output) + # Connect with a valid credentials. + opts = {"-u": "test", "-p": "password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "test_app", empty_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ username and password are not supported with a" + + " connection via a control socket", + output, + ) - # Connect with environment variables. - env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, "test_app", empty_file, env=env) - assert ret + # Connect with environment variables. + env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, "test_app", empty_file, env=env + ) + assert ret - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_connect_to_multi_instances_app(tt_cmd, tmpdir_with_cfg): @@ -675,27 +721,30 @@ def test_connect_to_multi_instances_app(tt_cmd, tmpdir_with_cfg): # Start instances. start_app(tt_cmd, tmpdir, app_name) + try: + # Check for start. + for instance in instances: + master_run_path = os.path.join(tmpdir, app_name, run_path, instance) + file = wait_file(master_run_path, control_socket, []) + assert file != "" - # Check for start. - for instance in instances: - master_run_path = os.path.join(tmpdir, app_name, run_path, instance) - file = wait_file(master_run_path, control_socket, []) - assert file != "" - - # Connect to a non-exist instance. - non_exist = app_name + ":" + "any_name" - ret, output = try_execute_on_instance(tt_cmd, tmpdir, non_exist, empty_file) - assert not ret - assert re.search(rf" ⨯ can't collect instance information for {non_exist}", output) + # Connect to a non-exist instance. + non_exist = app_name + ":" + "any_name" + ret, output = try_execute_on_instance(tt_cmd, tmpdir, non_exist, empty_file) + assert not ret + assert re.search( + rf" ⨯ can't collect instance information for {non_exist}", output + ) - # Connect to instances. - for instance in instances: - full_name = app_name + ":" + instance - ret, _ = try_execute_on_instance(tt_cmd, tmpdir, full_name, empty_file) - assert ret + # Connect to instances. + for instance in instances: + full_name = app_name + ":" + instance + ret, _ = try_execute_on_instance(tt_cmd, tmpdir, full_name, empty_file) + assert ret - # Stop the Instance. - stop_app(tt_cmd, tmpdir, app_name) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, app_name) def test_connect_to_multi_instances_app_credentials(tt_cmd, tmpdir_with_cfg): @@ -713,164 +762,206 @@ def test_connect_to_multi_instances_app_credentials(tt_cmd, tmpdir_with_cfg): # Start instances. start_app(tt_cmd, tmpdir, app_name) + try: + # Check for start. + master_run_path = os.path.join(tmpdir, app_name, run_path, "master") + file = wait_file(master_run_path, control_socket, []) + assert file != "" - # Check for start. - master_run_path = os.path.join(tmpdir, app_name, run_path, "master") - file = wait_file(master_run_path, control_socket, []) - assert file != "" - - # Connect with a wrong credentials. - full_name = app_name + ":master" - opts = {"-u": "test", "-p": "wrong_password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, full_name, empty_file, opts=opts) - assert not ret - assert re.search(r" ⨯ username and password are not supported with a" + - " connection via a control socket", output) + # Connect with a wrong credentials. + full_name = app_name + ":master" + opts = {"-u": "test", "-p": "wrong_password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, full_name, empty_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ username and password are not supported with a" + + " connection via a control socket", + output, + ) - # Connect with a valid credentials. - full_name = app_name + ":master" - opts = {"-u": "test", "-p": "password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, full_name, empty_file, opts=opts) - assert not ret - assert re.search(r" ⨯ username and password are not supported with a" + - " connection via a control socket", output) + # Connect with a valid credentials. + full_name = app_name + ":master" + opts = {"-u": "test", "-p": "password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, full_name, empty_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ username and password are not supported with a" + + " connection via a control socket", + output, + ) - # Connect with environment variables. - env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, full_name, empty_file, env=env) - assert ret + # Connect with environment variables. + env = {"TT_CLI_USERNAME": "test", "TT_CLI_PASSWORD": "wrong_password"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, full_name, empty_file, env=env + ) + assert ret - # Stop the Instance. - stop_app(tt_cmd, tmpdir, app_name) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, app_name) def test_connect_language_default_lua(tt_cmd, tmpdir_with_cfg): tmpdir = tmpdir_with_cfg test_app, lua_file, sql_file = prepare_test_app_languages(tt_cmd, tmpdir) + try: + # Execute Lua-code. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file) + assert ret + assert re.search(r"Hello, world", output) - # Execute Lua-code. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file) - assert ret - assert re.search(r"Hello, world", output) - - # Execute SQL-code. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file) - assert ret - assert re.search(r"metadata:", output) is None - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, test_app) + # Execute SQL-code. + ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file) + assert ret + assert re.search(r"metadata:", output) is None + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, test_app) def test_connect_language_lua(tt_cmd, tmpdir_with_cfg): tmpdir = tmpdir_with_cfg test_app, lua_file, sql_file = prepare_test_app_languages(tt_cmd, tmpdir) + try: + skip_if_language_unsupported(tt_cmd, tmpdir, test_app) - skip_if_language_unsupported(tt_cmd, tmpdir, test_app) - - # Execute Lua-code. - opts = {"-l": "lua"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file, opts=opts) - assert ret - assert re.search(r"Hello, world", output) - - # Execute SQL-code. - for lang in ["lua", "LuA", "LUA"]: - opts = {"-l": lang} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file, opts=opts) + # Execute Lua-code. + opts = {"-l": "lua"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, lua_file, opts=opts + ) assert ret - assert re.search(r"metadata:", output) is None + assert re.search(r"Hello, world", output) + + # Execute SQL-code. + for lang in ["lua", "LuA", "LUA"]: + opts = {"-l": lang} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, sql_file, opts=opts + ) + assert ret + assert re.search(r"metadata:", output) is None - # Stop the Instance. - stop_app(tt_cmd, tmpdir, test_app) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, test_app) def test_connect_language_sql(tt_cmd, tmpdir_with_cfg): tmpdir = tmpdir_with_cfg test_app, lua_file, sql_file = prepare_test_app_languages(tt_cmd, tmpdir) + try: + skip_if_language_unsupported(tt_cmd, tmpdir, test_app) - skip_if_language_unsupported(tt_cmd, tmpdir, test_app) - - # Execute Lua-code. - opts = {"-l": "sql"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file, opts=opts) - assert ret - assert re.search(r"Hello, world", output) is None - - # Execute SQL-code. - for lang in ["sql", "SqL", "SQL"]: - opts = {"-l": lang} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file, opts=opts) + # Execute Lua-code. + opts = {"-l": "sql"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, lua_file, opts=opts + ) assert ret - assert re.search(r"metadata:", output) + assert re.search(r"Hello, world", output) is None + + # Execute SQL-code. + for lang in ["sql", "SqL", "SQL"]: + opts = {"-l": lang} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, sql_file, opts=opts + ) + assert ret + assert re.search(r"metadata:", output) - # Stop the Instance. - stop_app(tt_cmd, tmpdir, test_app) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, test_app) def test_connect_language_l_equal_language(tt_cmd, tmpdir_with_cfg): tmpdir = tmpdir_with_cfg test_app, lua_file, sql_file = prepare_test_app_languages(tt_cmd, tmpdir) + try: + skip_if_language_unsupported(tt_cmd, tmpdir, test_app) - skip_if_language_unsupported(tt_cmd, tmpdir, test_app) - - for opt in ["-l", "--language"]: - # Execute Lua-code. - opts = {opt: "sql"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file, opts=opts) - assert ret - assert re.search(r"Hello, world", output) is None + for opt in ["-l", "--language"]: + # Execute Lua-code. + opts = {opt: "sql"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, lua_file, opts=opts + ) + assert ret + assert re.search(r"Hello, world", output) is None - # Execute SQL-code. - opts = {opt: "sql"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file, opts=opts) - assert ret - assert re.search(r"metadata:", output) + # Execute SQL-code. + opts = {opt: "sql"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, sql_file, opts=opts + ) + assert ret + assert re.search(r"metadata:", output) - # Stop the Instance. - stop_app(tt_cmd, tmpdir, test_app) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, test_app) def test_connect_language_invalid(tt_cmd, tmpdir_with_cfg): tmpdir = tmpdir_with_cfg test_app, lua_file, sql_file = prepare_test_app_languages(tt_cmd, tmpdir) + try: + # Execute Lua-code. + opts = {"-l": "invalid"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, lua_file, opts=opts + ) + assert not ret + assert re.search(r" ⨯ unsupported language: invalid", output) - # Execute Lua-code. - opts = {"-l": "invalid"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file, opts=opts) - assert not ret - assert re.search(r" ⨯ unsupported language: invalid", output) - - # Execute SQL-code. - opts = {"-l": "invalid"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file, opts=opts) - assert not ret - assert re.search(r" ⨯ unsupported language: invalid", output) + # Execute SQL-code. + opts = {"-l": "invalid"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, sql_file, opts=opts + ) + assert not ret + assert re.search(r" ⨯ unsupported language: invalid", output) - # Stop the Instance. - stop_app(tt_cmd, tmpdir, test_app) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, test_app) def test_connect_language_set_if_unsupported(tt_cmd, tmpdir_with_cfg): tmpdir = tmpdir_with_cfg test_app, lua_file, sql_file = prepare_test_app_languages(tt_cmd, tmpdir) + try: + skip_if_language_supported(tt_cmd, tmpdir, test_app) - skip_if_language_supported(tt_cmd, tmpdir, test_app) - - # Execute Lua-code. - opts = {"-l": "lua"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, lua_file, opts=opts) - assert not ret - assert re.search(r" ⨯ unable to change a language: unexpected response:", output) + # Execute Lua-code. + opts = {"-l": "lua"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, lua_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ unable to change a language: unexpected response:", output + ) - # Execute SQL-code. - opts = {"-l": "sql"} - ret, output = try_execute_on_instance(tt_cmd, tmpdir, test_app, sql_file, opts=opts) - assert not ret - assert re.search(r" ⨯ unable to change a language: unexpected response:", output) + # Execute SQL-code. + opts = {"-l": "sql"} + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, test_app, sql_file, opts=opts + ) + assert not ret + assert re.search( + r" ⨯ unable to change a language: unexpected response:", output + ) - # Stop the Instance. - stop_app(tt_cmd, tmpdir, test_app) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, test_app) def test_output_format_lua(tt_cmd, tmpdir_with_cfg): @@ -883,87 +974,81 @@ def test_output_format_lua(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" - - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="2+2", - opts={'-x': 'lua'} - ) - assert ret - assert output == "4;\n" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="2+2", opts={"-x": "lua"} + ) + assert ret + assert output == "4;\n" - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="\n", - opts={'-x': 'lua'} - ) - assert ret - assert output == ";\n" + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="\n", opts={"-x": "lua"} + ) + assert ret + assert output == ";\n" - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="1,2,3", - opts={'-x': 'lua'} - ) - assert ret - assert output == "1, 2, 3;\n" + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="1,2,3", opts={"-x": "lua"} + ) + assert ret + assert output == "1, 2, 3;\n" - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="1,\"2\",3", - opts={'-x': 'lua'} - ) - assert ret - assert output == "1, \"2\", 3;\n" + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin='1,"2",3', opts={"-x": "lua"} + ) + assert ret + assert output == '1, "2", 3;\n' - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="{1, 2, 3}", - opts={'-x': 'lua'} - ) - assert ret - assert output == "{1, 2, 3};\n" + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{1, 2, 3}", opts={"-x": "lua"} + ) + assert ret + assert output == "{1, 2, 3};\n" - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin='{10,20,box.NULL,30},{},{box.NULL},{data="hello world"}', - opts={'-x': 'lua'} - ) - assert ret - assert output == '{10, 20, nil, 30}, {}, {nil}, {data = "hello world"};\n' + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin='{10,20,box.NULL,30},{},{box.NULL},{data="hello world"}', + opts={"-x": "lua"}, + ) + assert ret + assert output == '{10, 20, nil, 30}, {}, {nil}, {data = "hello world"};\n' - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin='error("test")', - opts={'-x': 'lua'} - ) - assert ret - assert output == '{error = "test"};\n' + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin='error("test")', opts={"-x": "lua"} + ) + assert ret + assert output == '{error = "test"};\n' - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true})"), - opts={'-x': 'lua'}) - assert ret - assert output == ('{1, 21, "Flint", true};\n') + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=("box.tuple.new({1,21,'Flint',true})"), + opts={"-x": "lua"}, + ) + assert ret + assert output == ('{1, 21, "Flint", true};\n') - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_lua_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): @@ -978,73 +1063,101 @@ def test_lua_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "lua"}, + ) + assert ret + assert output == ('{1, 21, "Flint", true};\n') - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'lua'}) - assert ret - assert output == ('{1, 21, "Flint", true};\n') + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "{1,2,3},box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "lua"}, + ) + assert ret + assert output == ( + '{1, 21, "Flint", true}, {2, 32, "Sparrow", "Jack", ' + '"cpt"}, {1, 2, 3}, {3, 33, "Morgan", true};\n' + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "{1,2,3},box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'lua'}) - assert ret - assert output == ('{1, 21, "Flint", true}, {2, 32, "Sparrow", "Jack", ' - '"cpt"}, {1, 2, 3}, {3, 33, "Morgan", true};\n') + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,187,'Sparrow'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'height','number'},{'name','string'}})})," + "2002,{box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({4,35,'Blackbeard'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}" + ), + opts={"-x": "lua"}, + ) + assert ret + assert output == ( + '{1, 21, "Flint"}, {2, 187, "Sparrow"}, 2002, ' + '{{3, 33, "Morgan", true}, {4, 35, "Blackbeard"}};\n' + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,187,'Sparrow'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'height','number'},{'name','string'}})})," - "2002,{box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({4,35,'Blackbeard'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}"), - opts={'-x': 'lua'}) - assert ret - assert output == ('{1, 21, "Flint"}, {2, 187, "Sparrow"}, 2002, ' - '{{3, 33, "Morgan", true}, {4, 35, "Blackbeard"}};\n') + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'," + "box.tuple.new({1,21,'Flint',{data={1,2}}}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "lua"}, + ) + assert ret + assert output == ('{1, 21, "Flint", {1, 21, "Flint", {data = {1, 2}}}};\n') - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'," - "box.tuple.new({1,21,'Flint',{data={1,2}}}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'lua'}) - assert ret - assert output == ('{1, 21, "Flint", {1, 21, "Flint", {data = {1, 2}}}};\n') + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_yaml_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): @@ -1059,88 +1172,116 @@ def test_yaml_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "yaml"}, + ) + assert ret + assert output == ("---\n" "- [1, 21, 'Flint', true]\n" "...\n\n") - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'yaml'}) - assert ret - assert output == ("---\n" - "- [1, 21, 'Flint', true]\n" - "...\n\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "{1,2,3},box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "yaml"}, + ) + assert ret + assert output == ( + "---\n" + "- [1, 21, 'Flint', true]\n" + "- [2, 32, 'Sparrow', 'Jack', 'cpt']\n" + "- - 1\n" + " - 2\n" + " - 3\n" + "- [3, 33, 'Morgan', true]\n" + "...\n\n" + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "{1,2,3},box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'yaml'}) - assert ret - assert output == ("---\n" - "- [1, 21, 'Flint', true]\n" - "- [2, 32, 'Sparrow', 'Jack', 'cpt']\n" - "- - 1\n" - " - 2\n" - " - 3\n" - "- [3, 33, 'Morgan', true]\n" - "...\n\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,187,'Sparrow'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'height','number'},{'name','string'}})})," - "2002,{box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({4,35,'Blackbeard'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}"), - opts={'-x': 'yaml'}) - assert ret - assert output == ("---\n" - "- [1, 21, 'Flint']\n" - "- [2, 187, 'Sparrow']\n" - "- 2002\n" - "- - [3, 33, 'Morgan', true]\n" - " - [4, 35, 'Blackbeard']\n" - "...\n\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'," - "box.tuple.new({1,21,'Flint',{data={1,2}}}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'yaml'}) - assert ret - assert output == ("---\n" - "- [1, 21, 'Flint', [1, 21, 'Flint', {'data': [1, 2]}]]\n" - "...\n\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,187,'Sparrow'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'height','number'},{'name','string'}})})," + "2002,{box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({4,35,'Blackbeard'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}" + ), + opts={"-x": "yaml"}, + ) + assert ret + assert output == ( + "---\n" + "- [1, 21, 'Flint']\n" + "- [2, 187, 'Sparrow']\n" + "- 2002\n" + "- - [3, 33, 'Morgan', true]\n" + " - [4, 35, 'Blackbeard']\n" + "...\n\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'," + "box.tuple.new({1,21,'Flint',{data={1,2}}}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "yaml"}, + ) + assert ret + assert output == ( + "---\n" + "- [1, 21, 'Flint', [1, 21, 'Flint', {'data': [1, 2]}]]\n" + "...\n\n" + ) + + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_table_output_format(tt_cmd, tmpdir_with_cfg): @@ -1153,312 +1294,376 @@ def test_table_output_format(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="2+2", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+\n" "| col1 |\n" "+------+\n" "| 4 |\n" "+------+\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="2+2", opts={'-x': 'table'}) - assert ret - assert output == ("+------+\n" - "| col1 |\n" - "+------+\n" - "| 4 |\n" - "+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="1,2,3", opts={'-x': 'table'}) - assert ret - assert output == ("+------+\n" - "| col1 |\n" - "+------+\n" - "| 1 |\n" - "+------+\n" - "| 2 |\n" - "+------+\n" - "| 3 |\n" - "+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{1,2,3}", opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+------+\n" - "| col1 | col2 | col3 |\n" - "+------+------+------+\n" - "| 1 | 2 | 3 |\n" - "+------+------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{10,20,30},{40,50,60},{70,80},{box.NULL,90}", - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+------+\n" - "| col1 | col2 | col3 |\n" - "+------+------+------+\n" - "| 10 | 20 | 30 |\n" - "+------+------+------+\n" - "| 40 | 50 | 60 |\n" - "+------+------+------+\n" - "| 70 | 80 | |\n" - "+------+------+------+\n" - "| nil | 90 | |\n" - "+------+------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="box.tuple.new({1,100,'Mike',{data=123,'test'},{10,20}})", - opts={'-x': 'table'}) - assert ret - assert output == ('+------+------+------+-------------------------+---------+\n' - '| col1 | col2 | col3 | col4 | col5 |\n' - '+------+------+------+-------------------------+---------+\n' - '| 1 | 100 | Mike | {"1":"test","data":123} | [10,20] |\n' - '+------+------+------+-------------------------+---------+\n') - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{ {10,20},{30,40} }", opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+\n" - "| col1 | col2 |\n" - "+------+------+\n" - "| 10 | 20 |\n" - "+------+------+\n" - "| 30 | 40 |\n" - "+------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{10,20},{30,40}", opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+\n" - "| col1 | col2 |\n" - "+------+------+\n" - "| 10 | 20 |\n" - "+------+------+\n" - "| 30 | 40 |\n" - "+------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{ {10,20},{30,40},true }", - opts={'-x': 'table'}) - assert ret - assert output == ("+---------+---------+------+\n" - "| col1 | col2 | col3 |\n" - "+---------+---------+------+\n" - "| [10,20] | [30,40] | true |\n" - "+---------+---------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{10,20},{30,40},true", - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+\n" - "| col1 | col2 |\n" - "+------+------+\n" - "| 10 | 20 |\n" - "+------+------+\n" - "| 30 | 40 |\n" - "+------+------+\n" - "+------+\n" - "| col1 |\n" - "+------+\n" - "| true |\n" - "+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{data=123,'Hi'},{data=321,'My'},{qwe=11}", - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+\n" - "| col1 | data |\n" - "+------+------+\n" - "| Hi | 123 |\n" - "+------+------+\n" - "| My | 321 |\n" - "+------+------+\n" - "+-----+\n" - "| qwe |\n" - "+-----+\n" - "| 11 |\n" - "+-----+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="{data=123,'Hi'}, {data=321,'My'}," + - "{qwe=11}, true, box.NULL, 2023, false, {10,20}, {30,40}, {50}", - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+\n" - "| col1 | data |\n" - "+------+------+\n" - "| Hi | 123 |\n" - "+------+------+\n" - "| My | 321 |\n" - "+------+------+\n" - "+-----+\n" - "| qwe |\n" - "+-----+\n" - "| 11 |\n" - "+-----+\n" - "+-------+\n" - "| col1 |\n" - "+-------+\n" - "| true |\n" - "+-------+\n" - "| nil |\n" - "+-------+\n" - "| 2023 |\n" - "+-------+\n" - "| false |\n" - "+-------+\n" - "+------+------+\n" - "| col1 | col2 |\n" - "+------+------+\n" - "| 10 | 20 |\n" - "+------+------+\n" - "| 30 | 40 |\n" - "+------+------+\n" - "| 50 | |\n" - "+------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true})"), - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+-------+------+\n" - "| col1 | col2 | col3 | col4 |\n" - "+------+------+-------+------+\n" - "| 1 | 21 | Flint | true |\n" - "+------+------+-------+------+\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="1,2,3", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+\n" + "| col1 |\n" + "+------+\n" + "| 1 |\n" + "+------+\n" + "| 2 |\n" + "+------+\n" + "| 3 |\n" + "+------+\n" + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("{box.tuple.new({1,21,'Flint',true}),1}"), - opts={'-x': 'table'}) - assert ret - assert output == ("+---------------------+------+\n" - "| col1 | col2 |\n" - "+---------------------+------+\n" - '| [1,21,"Flint",true] | 1 |\n' - "+---------------------+------+\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{1,2,3}", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+------+------+\n" + "| col1 | col2 | col3 |\n" + "+------+------+------+\n" + "| 1 | 2 | 3 |\n" + "+------+------+------+\n" + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("{box.tuple.new({1,21,'Flint',true}),{2,21,'Alex'}}"), - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+-------+------+\n" - "| col1 | col2 | col3 | col4 |\n" - "+------+------+-------+------+\n" - "| 1 | 21 | Flint | true |\n" - "+------+------+-------+------+\n" - "| 2 | 21 | Alex | |\n" - "+------+------+-------+------+\n") - - if not is_tarantool_major_one(): # Execute stdin. ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="box.execute('select 1 as FOO, 30, 50, 4+4 as DATA')", - opts={'-x': 'table'}) + tt_cmd, + tmpdir, + uri, + stdin="{10,20,30},{40,50,60},{70,80},{box.NULL,90}", + opts={"-x": "table"}, + ) assert ret - assert output == ("+-----+----------+----------+------+\n" - "| FOO | COLUMN_1 | COLUMN_2 | DATA |\n" - "+-----+----------+----------+------+\n" - "| 1 | 30 | 50 | 8 |\n" - "+-----+----------+----------+------+\n") + assert output == ( + "+------+------+------+\n" + "| col1 | col2 | col3 |\n" + "+------+------+------+\n" + "| 10 | 20 | 30 |\n" + "+------+------+------+\n" + "| 40 | 50 | 60 |\n" + "+------+------+------+\n" + "| 70 | 80 | |\n" + "+------+------+------+\n" + "| nil | 90 | |\n" + "+------+------+------+\n" + ) # Execute stdin. - if (tarantool_major_version >= 3 or - (tarantool_major_version == 2 and tarantool_minor_version >= 11)): - select = "select * from seqscan table1" - else: - select = "select * from table1" - - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin=f"box.execute('{select}')", - opts={'-x': 'table'}) - assert ret - assert output == ("+---------+-------------------+\n" - "| COLUMN1 | COLUMN2 |\n" - "+---------+-------------------+\n" - "| 10 | Hello SQL world! |\n" - "+---------+-------------------+\n" - "| 20 | Hello LUA world! |\n" - "+---------+-------------------+\n" - "| 30 | Hello YAML world! |\n" - "+---------+-------------------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="error('test')", opts={'-x': 'table'}) - assert ret - assert output == ("+-------+\n" - "| error |\n" - "+-------+\n" - "| test |\n" - "+-------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin=" ", opts={'-x': 'table'}) - assert ret - assert output == ("+------+\n" - "| col1 |\n" - "+------+\n" - "| |\n" - "+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="nil", opts={'-x': 'table'}) - assert ret - assert output == ("+------+\n" - "| col1 |\n" - "+------+\n" - "| nil |\n" - "+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{{{2+2}}}", opts={'-x': 'table'}) - assert ret - assert output == ("+------+\n" - "| col1 |\n" - "+------+\n" - "| [4] |\n" - "+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{{{{2+2}}}}", opts={'-x': 'table'}) - assert ret - assert output == ("+-------+\n" - "| col1 |\n" - "+-------+\n" - "| [[4]] |\n" - "+-------+\n") + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="box.tuple.new({1,100,'Mike',{data=123,'test'},{10,20}})", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+------+------+-------------------------+---------+\n" + "| col1 | col2 | col3 | col4 | col5 |\n" + "+------+------+------+-------------------------+---------+\n" + '| 1 | 100 | Mike | {"1":"test","data":123} | [10,20] |\n' + "+------+------+------+-------------------------+---------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{ {10,20},{30,40} }", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+------+\n" + "| col1 | col2 |\n" + "+------+------+\n" + "| 10 | 20 |\n" + "+------+------+\n" + "| 30 | 40 |\n" + "+------+------+\n" + ) - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{10,20},{30,40}", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+------+\n" + "| col1 | col2 |\n" + "+------+------+\n" + "| 10 | 20 |\n" + "+------+------+\n" + "| 30 | 40 |\n" + "+------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="{ {10,20},{30,40},true }", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+---------+---------+------+\n" + "| col1 | col2 | col3 |\n" + "+---------+---------+------+\n" + "| [10,20] | [30,40] | true |\n" + "+---------+---------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{10,20},{30,40},true", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+------+\n" + "| col1 | col2 |\n" + "+------+------+\n" + "| 10 | 20 |\n" + "+------+------+\n" + "| 30 | 40 |\n" + "+------+------+\n" + "+------+\n" + "| col1 |\n" + "+------+\n" + "| true |\n" + "+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="{data=123,'Hi'},{data=321,'My'},{qwe=11}", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+------+\n" + "| col1 | data |\n" + "+------+------+\n" + "| Hi | 123 |\n" + "+------+------+\n" + "| My | 321 |\n" + "+------+------+\n" + "+-----+\n" + "| qwe |\n" + "+-----+\n" + "| 11 |\n" + "+-----+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="{data=123,'Hi'}, {data=321,'My'}," + + "{qwe=11}, true, box.NULL, 2023, false, {10,20}, {30,40}, {50}", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+------+\n" + "| col1 | data |\n" + "+------+------+\n" + "| Hi | 123 |\n" + "+------+------+\n" + "| My | 321 |\n" + "+------+------+\n" + "+-----+\n" + "| qwe |\n" + "+-----+\n" + "| 11 |\n" + "+-----+\n" + "+-------+\n" + "| col1 |\n" + "+-------+\n" + "| true |\n" + "+-------+\n" + "| nil |\n" + "+-------+\n" + "| 2023 |\n" + "+-------+\n" + "| false |\n" + "+-------+\n" + "+------+------+\n" + "| col1 | col2 |\n" + "+------+------+\n" + "| 10 | 20 |\n" + "+------+------+\n" + "| 30 | 40 |\n" + "+------+------+\n" + "| 50 | |\n" + "+------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=("box.tuple.new({1,21,'Flint',true})"), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+------+-------+------+\n" + "| col1 | col2 | col3 | col4 |\n" + "+------+------+-------+------+\n" + "| 1 | 21 | Flint | true |\n" + "+------+------+-------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=("{box.tuple.new({1,21,'Flint',true}),1}"), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+---------------------+------+\n" + "| col1 | col2 |\n" + "+---------------------+------+\n" + '| [1,21,"Flint",true] | 1 |\n' + "+---------------------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=("{box.tuple.new({1,21,'Flint',true}),{2,21,'Alex'}}"), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+------+-------+------+\n" + "| col1 | col2 | col3 | col4 |\n" + "+------+------+-------+------+\n" + "| 1 | 21 | Flint | true |\n" + "+------+------+-------+------+\n" + "| 2 | 21 | Alex | |\n" + "+------+------+-------+------+\n" + ) + + if not is_tarantool_major_one(): + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="box.execute('select 1 as FOO, 30, 50, 4+4 as DATA')", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+-----+----------+----------+------+\n" + "| FOO | COLUMN_1 | COLUMN_2 | DATA |\n" + "+-----+----------+----------+------+\n" + "| 1 | 30 | 50 | 8 |\n" + "+-----+----------+----------+------+\n" + ) + + # Execute stdin. + if tarantool_major_version >= 3 or ( + tarantool_major_version == 2 and tarantool_minor_version >= 11 + ): + select = "select * from seqscan table1" + else: + select = "select * from table1" + + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=f"box.execute('{select}')", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+---------+-------------------+\n" + "| COLUMN1 | COLUMN2 |\n" + "+---------+-------------------+\n" + "| 10 | Hello SQL world! |\n" + "+---------+-------------------+\n" + "| 20 | Hello LUA world! |\n" + "+---------+-------------------+\n" + "| 30 | Hello YAML world! |\n" + "+---------+-------------------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="error('test')", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+-------+\n" "| error |\n" "+-------+\n" "| test |\n" "+-------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin=" ", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+\n" "| col1 |\n" "+------+\n" "| |\n" "+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="nil", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+\n" "| col1 |\n" "+------+\n" "| nil |\n" "+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{{{2+2}}}", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+------+\n" "| col1 |\n" "+------+\n" "| [4] |\n" "+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="{{{{2+2}}}}", opts={"-x": "table"} + ) + assert ret + assert output == ( + "+-------+\n" "| col1 |\n" "+-------+\n" "| [[4]] |\n" "+-------+\n" + ) + + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_table_output_format_for_tuples_no_format(tt_cmd, tmpdir_with_cfg): @@ -1473,36 +1678,46 @@ def test_table_output_format_for_tuples_no_format(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="box.space.customers:select()", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+-----------+------+\n" + "| col1 | col2 | col3 |\n" + "+------+-----------+------+\n" + "| 1 | Elizabeth | 12 |\n" + "+------+-----------+------+\n" + "| 2 | Mary | 46 |\n" + "+------+-----------+------+\n" + "| 3 | David | 33 |\n" + "+------+-----------+------+\n" + "| 4 | William | 81 |\n" + "+------+-----------+------+\n" + "| 5 | Jack | 35 |\n" + "+------+-----------+------+\n" + "| 6 | William | 25 |\n" + "+------+-----------+------+\n" + "| 7 | Elizabeth | 18 |\n" + "+------+-----------+------+\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="box.space.customers:select()", - opts={'-x': 'table'}) - assert ret - assert output == ("+------+-----------+------+\n" - "| col1 | col2 | col3 |\n" - "+------+-----------+------+\n" - "| 1 | Elizabeth | 12 |\n" - "+------+-----------+------+\n" - "| 2 | Mary | 46 |\n" - "+------+-----------+------+\n" - "| 3 | David | 33 |\n" - "+------+-----------+------+\n" - "| 4 | William | 81 |\n" - "+------+-----------+------+\n" - "| 5 | Jack | 35 |\n" - "+------+-----------+------+\n" - "| 6 | William | 25 |\n" - "+------+-----------+------+\n" - "| 7 | Elizabeth | 18 |\n" - "+------+-----------+------+\n") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_table_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): @@ -1517,251 +1732,317 @@ def test_table_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="box.space.customers:select()", + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----------+-----+\n" + "| id | name | age |\n" + "+----+-----------+-----+\n" + "| 1 | Elizabeth | 12 |\n" + "+----+-----------+-----+\n" + "| 2 | Mary | 46 |\n" + "+----+-----------+-----+\n" + "| 3 | David | 33 |\n" + "+----+-----------+-----+\n" + "| 4 | William | 81 |\n" + "+----+-----------+-----+\n" + "| 5 | Jack | 35 |\n" + "+----+-----------+-----+\n" + "| 6 | William | 25 |\n" + "+----+-----------+-----+\n" + "| 7 | Elizabeth | 18 |\n" + "+----+-----------+-----+\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="box.space.customers:select()", - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----------+-----+\n" - "| id | name | age |\n" - "+----+-----------+-----+\n" - "| 1 | Elizabeth | 12 |\n" - "+----+-----------+-----+\n" - "| 2 | Mary | 46 |\n" - "+----+-----------+-----+\n" - "| 3 | David | 33 |\n" - "+----+-----------+-----+\n" - "| 4 | William | 81 |\n" - "+----+-----------+-----+\n" - "| 5 | Jack | 35 |\n" - "+----+-----------+-----+\n" - "| 6 | William | 25 |\n" - "+----+-----------+-----+\n" - "| 7 | Elizabeth | 18 |\n" - "+----+-----------+-----+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----+-------+------+\n" - "| id | age | name | col1 |\n" - "+----+-----+-------+------+\n" - "| 1 | 21 | Flint | true |\n" - "+----+-----+-------+------+\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----+-------+------+\n" + "| id | age | name | col1 |\n" + "+----+-----+-------+------+\n" + "| 1 | 21 | Flint | true |\n" + "+----+-----+-------+------+\n" + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("{box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})}),1}"), - opts={'-x': 'table'}) - assert ret - assert output == ("+---------------------+------+\n" - "| col1 | col2 |\n" - "+---------------------+------+\n" - '| [1,21,"Flint",true] | 1 |\n' - "+---------------------+------+\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "{box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})}),1}" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+---------------------+------+\n" + "| col1 | col2 |\n" + "+---------------------+------+\n" + '| [1,21,"Flint",true] | 1 |\n' + "+---------------------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "{box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})}),{2,21,'Alex'}}" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+------+------+-------+------+\n" + "| col1 | col2 | col3 | col4 |\n" + "+------+------+-------+------+\n" + "| 1 | 21 | Flint | true |\n" + "+------+------+-------+------+\n" + "| 2 | 21 | Alex | |\n" + "+------+------+-------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({12,187,'Flint',false}," + "{format=box.tuple.format.new({{'id','number'}," + "{'height','number'},{'name','string'}})})," + "2002,{1,2,3},box.space.customers:select()" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----+-------+------+\n" + "| id | age | name | col1 |\n" + "+----+-----+-------+------+\n" + "| 1 | 21 | Flint | true |\n" + "+----+-----+-------+------+\n" + "+----+--------+-------+-------+\n" + "| id | height | name | col1 |\n" + "+----+--------+-------+-------+\n" + "| 12 | 187 | Flint | false |\n" + "+----+--------+-------+-------+\n" + "+------+\n" + "| col1 |\n" + "+------+\n" + "| 2002 |\n" + "+------+\n" + "+------+------+------+\n" + "| col1 | col2 | col3 |\n" + "+------+------+------+\n" + "| 1 | 2 | 3 |\n" + "+------+------+------+\n" + "+----+-----------+-----+\n" + "| id | name | age |\n" + "+----+-----------+-----+\n" + "| 1 | Elizabeth | 12 |\n" + "+----+-----------+-----+\n" + "| 2 | Mary | 46 |\n" + "+----+-----------+-----+\n" + "| 3 | David | 33 |\n" + "+----+-----------+-----+\n" + "| 4 | William | 81 |\n" + "+----+-----------+-----+\n" + "| 5 | Jack | 35 |\n" + "+----+-----------+-----+\n" + "| 6 | William | 25 |\n" + "+----+-----------+-----+\n" + "| 7 | Elizabeth | 18 |\n" + "+----+-----------+-----+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,32,'Sparrow'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "{1,2,3},box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----+---------+------+\n" + "| id | age | name | col1 |\n" + "+----+-----+---------+------+\n" + "| 1 | 21 | Flint | true |\n" + "+----+-----+---------+------+\n" + "| 2 | 32 | Sparrow | |\n" + "+----+-----+---------+------+\n" + "+------+------+------+\n" + "| col1 | col2 | col3 |\n" + "+------+------+------+\n" + "| 1 | 2 | 3 |\n" + "+------+------+------+\n" + "+----+-----+--------+------+\n" + "| id | age | name | col1 |\n" + "+----+-----+--------+------+\n" + "| 3 | 33 | Morgan | true |\n" + "+----+-----+--------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "{1,2,3},box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----+---------+------+------+\n" + "| id | age | name | col1 | col2 |\n" + "+----+-----+---------+------+------+\n" + "| 1 | 21 | Flint | true | |\n" + "+----+-----+---------+------+------+\n" + "| 2 | 32 | Sparrow | Jack | cpt |\n" + "+----+-----+---------+------+------+\n" + "+------+------+------+\n" + "| col1 | col2 | col3 |\n" + "+------+------+------+\n" + "| 1 | 2 | 3 |\n" + "+------+------+------+\n" + "+----+-----+--------+------+\n" + "| id | age | name | col1 |\n" + "+----+-----+--------+------+\n" + "| 3 | 33 | Morgan | true |\n" + "+----+-----+--------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,187,'Sparrow'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'height','number'},{'name','string'}})})," + "2002,{box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({4,35,'Blackbeard'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----+-------+\n" + "| id | age | name |\n" + "+----+-----+-------+\n" + "| 1 | 21 | Flint |\n" + "+----+-----+-------+\n" + "+----+--------+---------+\n" + "| id | height | name |\n" + "+----+--------+---------+\n" + "| 2 | 187 | Sparrow |\n" + "+----+--------+---------+\n" + "+------+\n" + "| col1 |\n" + "+------+\n" + "| 2002 |\n" + "+------+\n" + "+----+-----+------------+------+\n" + "| id | age | name | col1 |\n" + "+----+-----+------------+------+\n" + "| 3 | 33 | Morgan | true |\n" + "+----+-----+------------+------+\n" + "| 4 | 35 | Blackbeard | |\n" + "+----+-----+------------+------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'," + "box.tuple.new({1,21,'Flint',{data={1,2}}}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "table"}, + ) + assert ret + assert output == ( + "+----+-----+-------+-------------------------------+\n" + "| id | age | name | col1 |\n" + "+----+-----+-------+-------------------------------+\n" + '| 1 | 21 | Flint | [1,21,"Flint",{"data":[1,2]}] |\n' + "+----+-----+-------+-------------------------------+\n" + ) - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("{box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})}),{2,21,'Alex'}}"), - opts={'-x': 'table'}) - assert ret - assert output == ("+------+------+-------+------+\n" - "| col1 | col2 | col3 | col4 |\n" - "+------+------+-------+------+\n" - "| 1 | 21 | Flint | true |\n" - "+------+------+-------+------+\n" - "| 2 | 21 | Alex | |\n" - "+------+------+-------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({12,187,'Flint',false}," - "{format=box.tuple.format.new({{'id','number'}," - "{'height','number'},{'name','string'}})})," - "2002,{1,2,3},box.space.customers:select()"), - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----+-------+------+\n" - "| id | age | name | col1 |\n" - "+----+-----+-------+------+\n" - "| 1 | 21 | Flint | true |\n" - "+----+-----+-------+------+\n" - "+----+--------+-------+-------+\n" - "| id | height | name | col1 |\n" - "+----+--------+-------+-------+\n" - "| 12 | 187 | Flint | false |\n" - "+----+--------+-------+-------+\n" - "+------+\n" - "| col1 |\n" - "+------+\n" - "| 2002 |\n" - "+------+\n" - "+------+------+------+\n" - "| col1 | col2 | col3 |\n" - "+------+------+------+\n" - "| 1 | 2 | 3 |\n" - "+------+------+------+\n" - "+----+-----------+-----+\n" - "| id | name | age |\n" - "+----+-----------+-----+\n" - "| 1 | Elizabeth | 12 |\n" - "+----+-----------+-----+\n" - "| 2 | Mary | 46 |\n" - "+----+-----------+-----+\n" - "| 3 | David | 33 |\n" - "+----+-----------+-----+\n" - "| 4 | William | 81 |\n" - "+----+-----------+-----+\n" - "| 5 | Jack | 35 |\n" - "+----+-----------+-----+\n" - "| 6 | William | 25 |\n" - "+----+-----------+-----+\n" - "| 7 | Elizabeth | 18 |\n" - "+----+-----------+-----+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,32,'Sparrow'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "{1,2,3},box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----+---------+------+\n" - "| id | age | name | col1 |\n" - "+----+-----+---------+------+\n" - "| 1 | 21 | Flint | true |\n" - "+----+-----+---------+------+\n" - "| 2 | 32 | Sparrow | |\n" - "+----+-----+---------+------+\n" - "+------+------+------+\n" - "| col1 | col2 | col3 |\n" - "+------+------+------+\n" - "| 1 | 2 | 3 |\n" - "+------+------+------+\n" - "+----+-----+--------+------+\n" - "| id | age | name | col1 |\n" - "+----+-----+--------+------+\n" - "| 3 | 33 | Morgan | true |\n" - "+----+-----+--------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "{1,2,3},box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----+---------+------+------+\n" - "| id | age | name | col1 | col2 |\n" - "+----+-----+---------+------+------+\n" - "| 1 | 21 | Flint | true | |\n" - "+----+-----+---------+------+------+\n" - "| 2 | 32 | Sparrow | Jack | cpt |\n" - "+----+-----+---------+------+------+\n" - "+------+------+------+\n" - "| col1 | col2 | col3 |\n" - "+------+------+------+\n" - "| 1 | 2 | 3 |\n" - "+------+------+------+\n" - "+----+-----+--------+------+\n" - "| id | age | name | col1 |\n" - "+----+-----+--------+------+\n" - "| 3 | 33 | Morgan | true |\n" - "+----+-----+--------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,187,'Sparrow'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'height','number'},{'name','string'}})})," - "2002,{box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({4,35,'Blackbeard'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}"), - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----+-------+\n" - "| id | age | name |\n" - "+----+-----+-------+\n" - "| 1 | 21 | Flint |\n" - "+----+-----+-------+\n" - "+----+--------+---------+\n" - "| id | height | name |\n" - "+----+--------+---------+\n" - "| 2 | 187 | Sparrow |\n" - "+----+--------+---------+\n" - "+------+\n" - "| col1 |\n" - "+------+\n" - "| 2002 |\n" - "+------+\n" - "+----+-----+------------+------+\n" - "| id | age | name | col1 |\n" - "+----+-----+------------+------+\n" - "| 3 | 33 | Morgan | true |\n" - "+----+-----+------------+------+\n" - "| 4 | 35 | Blackbeard | |\n" - "+----+-----+------------+------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'," - "box.tuple.new({1,21,'Flint',{data={1,2}}}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'table'}) - assert ret - assert output == ("+----+-----+-------+-------------------------------+\n" - "| id | age | name | col1 |\n" - "+----+-----+-------+-------------------------------+\n" - '| 1 | 21 | Flint | [1,21,"Flint",{"data":[1,2]}] |\n' - "+----+-----+-------+-------------------------------+\n") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_ttable_output_format(tt_cmd, tmpdir_with_cfg): @@ -1777,69 +2058,83 @@ def test_ttable_output_format(tt_cmd, tmpdir_with_cfg): print(tt_cmd) print("\n\n") start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="2+2", opts={"-x": "ttable"} + ) + assert ret + assert output == ("+------+---+\n" "| col1 | 4 |\n" "+------+---+\n") - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="2+2", opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+---+\n" - "| col1 | 4 |\n" - "+------+---+\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="1,2,3", opts={"-x": "ttable"} + ) + assert ret + assert output == ( + "+------+---+---+---+\n" + "| col1 | 1 | 2 | 3 |\n" + "+------+---+---+---+\n" + ) - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="1,2,3", opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+---+---+---+\n" - "| col1 | 1 | 2 | 3 |\n" - "+------+---+---+---+\n") - - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="{10,20,30},{40,50,60},{70,80},{box.NULL,90}", - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+----+----+----+-----+\n" - "| col1 | 10 | 40 | 70 | nil |\n" - "+------+----+----+----+-----+\n" - "| col2 | 20 | 50 | 80 | 90 |\n" - "+------+----+----+----+-----+\n" - "| col3 | 30 | 60 | | |\n" - "+------+----+----+----+-----+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="{data=123,'Hi'},{data=321,'My'}," + - "{qwe=11},true,box.NULL,2023,false,{10,20},{30,40},{50}", - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-----+-----+\n" - "| col1 | Hi | My |\n" - "+------+-----+-----+\n" - "| data | 123 | 321 |\n" - "+------+-----+-----+\n" - "+-----+----+\n" - "| qwe | 11 |\n" - "+-----+----+\n" - "+------+------+-----+------+-------+\n" - "| col1 | true | nil | 2023 | false |\n" - "+------+------+-----+------+-------+\n" - "+------+----+----+----+\n" - "| col1 | 10 | 30 | 50 |\n" - "+------+----+----+----+\n" - "| col2 | 20 | 40 | |\n" - "+------+----+----+----+\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="{10,20,30},{40,50,60},{70,80},{box.NULL,90}", + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+----+----+----+-----+\n" + "| col1 | 10 | 40 | 70 | nil |\n" + "+------+----+----+----+-----+\n" + "| col2 | 20 | 50 | 80 | 90 |\n" + "+------+----+----+----+-----+\n" + "| col3 | 30 | 60 | | |\n" + "+------+----+----+----+-----+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="{data=123,'Hi'},{data=321,'My'}," + + "{qwe=11},true,box.NULL,2023,false,{10,20},{30,40},{50}", + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-----+-----+\n" + "| col1 | Hi | My |\n" + "+------+-----+-----+\n" + "| data | 123 | 321 |\n" + "+------+-----+-----+\n" + "+-----+----+\n" + "| qwe | 11 |\n" + "+-----+----+\n" + "+------+------+-----+------+-------+\n" + "| col1 | true | nil | 2023 | false |\n" + "+------+------+-----+------+-------+\n" + "+------+----+----+----+\n" + "| col1 | 10 | 30 | 50 |\n" + "+------+----+----+----+\n" + "| col2 | 20 | 40 | |\n" + "+------+----+----+----+\n" + ) + + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_ttable_output_format_for_tuples_no_format(tt_cmd, tmpdir_with_cfg): @@ -1854,33 +2149,42 @@ def test_ttable_output_format_for_tuples_no_format(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" - - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="box.space.customers:select()", - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-----------+------+-------+---------+" - "------+---------+-----------+\n" - "| col1 | 1 | 2 | 3 | 4 |" - " 5 | 6 | 7 |\n" - "+------+-----------+------+-------+---------+" - "------+---------+-----------+\n" - "| col2 | Elizabeth | Mary | David | William |" - " Jack | William | Elizabeth |\n" - "+------+-----------+------+-------+---------+" - "------+---------+-----------+\n" - "| col3 | 12 | 46 | 33 | 81 |" - " 35 | 25 | 18 |\n" - "+------+-----------+------+-------+---------+" - "------+---------+-----------+\n") + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="box.space.customers:select()", + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-----------+------+-------+---------+" + "------+---------+-----------+\n" + "| col1 | 1 | 2 | 3 | 4 |" + " 5 | 6 | 7 |\n" + "+------+-----------+------+-------+---------+" + "------+---------+-----------+\n" + "| col2 | Elizabeth | Mary | David | William |" + " Jack | William | Elizabeth |\n" + "+------+-----------+------+-------+---------+" + "------+---------+-----------+\n" + "| col3 | 12 | 46 | 33 | 81 |" + " 35 | 25 | 18 |\n" + "+------+-----------+------+-------+---------+" + "------+---------+-----------+\n" + ) + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_ttable_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): @@ -1895,192 +2199,230 @@ def test_ttable_output_format_for_tuples(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin="box.space.customers:select()", + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + "| id | 1 | 2 | 3 | 4 | 5 |" + " 6 | 7 |\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + "| name | Elizabeth | Mary | David | William | Jack |" + " William | Elizabeth |\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + "| age | 12 | 46 | 33 | 81 | 35 |" + " 25 | 18 |\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="box.space.customers:select()", - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-----------+------+-------+---------+------+" - "---------+-----------+\n" - "| id | 1 | 2 | 3 | 4 | 5 |" - " 6 | 7 |\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n" - "| name | Elizabeth | Mary | David | William | Jack |" - " William | Elizabeth |\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n" - "| age | 12 | 46 | 33 | 81 | 35 |" - " 25 | 18 |\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-------+\n" - "| id | 1 |\n" - "+------+-------+\n" - "| age | 21 |\n" - "+------+-------+\n" - "| name | Flint |\n" - "+------+-------+\n" - "| col1 | true |\n" - "+------+-------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({12,187,'Flint',false}," - "{format=box.tuple.format.new({{'id','number'}," - "{'height','number'},{'name','string'}})})," - "2002,{1,2,3},box.space.customers:select()"), - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-------+\n" - "| id | 1 |\n" - "+------+-------+\n" - "| age | 21 |\n" - "+------+-------+\n" - "| name | Flint |\n" - "+------+-------+\n" - "| col1 | true |\n" - "+------+-------+\n" - "+--------+-------+\n" - "| id | 12 |\n" - "+--------+-------+\n" - "| height | 187 |\n" - "+--------+-------+\n" - "| name | Flint |\n" - "+--------+-------+\n" - "| col1 | false |\n" - "+--------+-------+\n" - "+------+------+\n" - "| col1 | 2002 |\n" - "+------+------+\n" - "+------+---+\n" - "| col1 | 1 |\n" - "+------+---+\n" - "| col2 | 2 |\n" - "+------+---+\n" - "| col3 | 3 |\n" - "+------+---+\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n" - "| id | 1 | 2 | 3 | 4 | 5 |" - " 6 | 7 |\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n" - "| name | Elizabeth | Mary | David | William | Jack |" - " William | Elizabeth |\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n" - "| age | 12 | 46 | 33 | 81 | 35 |" - " 25 | 18 |\n" - "+------+-----------+------+-------+---------+------+" - "---------+-----------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "{1,2,3},box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})"), - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-------+---------+\n" - "| id | 1 | 2 |\n" - "+------+-------+---------+\n" - "| age | 21 | 32 |\n" - "+------+-------+---------+\n" - "| name | Flint | Sparrow |\n" - "+------+-------+---------+\n" - "| col1 | true | Jack |\n" - "+------+-------+---------+\n" - "| col2 | | cpt |\n" - "+------+-------+---------+\n" - "+------+---+\n" - "| col1 | 1 |\n" - "+------+---+\n" - "| col2 | 2 |\n" - "+------+---+\n" - "| col3 | 3 |\n" - "+------+---+\n" - "+------+--------+\n" - "| id | 3 |\n" - "+------+--------+\n" - "| age | 33 |\n" - "+------+--------+\n" - "| name | Morgan |\n" - "+------+--------+\n" - "| col1 | true |\n" - "+------+--------+\n") - - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("box.tuple.new({1,21,'Flint'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({2,187,'Sparrow'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'height','number'},{'name','string'}})})," - "2002,{box.tuple.new({3,33,'Morgan',true}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})," - "box.tuple.new({4,35,'Blackbeard'}," - "{format=box.tuple.format.new({{'id','number'}," - "{'age','number'},{'name','string'}})})}"), - opts={'-x': 'ttable'}) - assert ret - assert output == ("+------+-------+\n" - "| id | 1 |\n" - "+------+-------+\n" - "| age | 21 |\n" - "+------+-------+\n" - "| name | Flint |\n" - "+------+-------+\n" - "+--------+---------+\n" - "| id | 2 |\n" - "+--------+---------+\n" - "| height | 187 |\n" - "+--------+---------+\n" - "| name | Sparrow |\n" - "+--------+---------+\n" - "+------+------+\n" - "| col1 | 2002 |\n" - "+------+------+\n" - "+------+--------+------------+\n" - "| id | 3 | 4 |\n" - "+------+--------+------------+\n" - "| age | 33 | 35 |\n" - "+------+--------+------------+\n" - "| name | Morgan | Blackbeard |\n" - "+------+--------+------------+\n" - "| col1 | true | |\n" - "+------+--------+------------+\n") + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-------+\n" + "| id | 1 |\n" + "+------+-------+\n" + "| age | 21 |\n" + "+------+-------+\n" + "| name | Flint |\n" + "+------+-------+\n" + "| col1 | true |\n" + "+------+-------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({12,187,'Flint',false}," + "{format=box.tuple.format.new({{'id','number'}," + "{'height','number'},{'name','string'}})})," + "2002,{1,2,3},box.space.customers:select()" + ), + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-------+\n" + "| id | 1 |\n" + "+------+-------+\n" + "| age | 21 |\n" + "+------+-------+\n" + "| name | Flint |\n" + "+------+-------+\n" + "| col1 | true |\n" + "+------+-------+\n" + "+--------+-------+\n" + "| id | 12 |\n" + "+--------+-------+\n" + "| height | 187 |\n" + "+--------+-------+\n" + "| name | Flint |\n" + "+--------+-------+\n" + "| col1 | false |\n" + "+--------+-------+\n" + "+------+------+\n" + "| col1 | 2002 |\n" + "+------+------+\n" + "+------+---+\n" + "| col1 | 1 |\n" + "+------+---+\n" + "| col2 | 2 |\n" + "+------+---+\n" + "| col3 | 3 |\n" + "+------+---+\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + "| id | 1 | 2 | 3 | 4 | 5 |" + " 6 | 7 |\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + "| name | Elizabeth | Mary | David | William | Jack |" + " William | Elizabeth |\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + "| age | 12 | 46 | 33 | 81 | 35 |" + " 25 | 18 |\n" + "+------+-----------+------+-------+---------+------+" + "---------+-----------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,32,'Sparrow','Jack','cpt'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "{1,2,3},box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})" + ), + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-------+---------+\n" + "| id | 1 | 2 |\n" + "+------+-------+---------+\n" + "| age | 21 | 32 |\n" + "+------+-------+---------+\n" + "| name | Flint | Sparrow |\n" + "+------+-------+---------+\n" + "| col1 | true | Jack |\n" + "+------+-------+---------+\n" + "| col2 | | cpt |\n" + "+------+-------+---------+\n" + "+------+---+\n" + "| col1 | 1 |\n" + "+------+---+\n" + "| col2 | 2 |\n" + "+------+---+\n" + "| col3 | 3 |\n" + "+------+---+\n" + "+------+--------+\n" + "| id | 3 |\n" + "+------+--------+\n" + "| age | 33 |\n" + "+------+--------+\n" + "| name | Morgan |\n" + "+------+--------+\n" + "| col1 | true |\n" + "+------+--------+\n" + ) + + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "box.tuple.new({1,21,'Flint'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({2,187,'Sparrow'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'height','number'},{'name','string'}})})," + "2002,{box.tuple.new({3,33,'Morgan',true}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})," + "box.tuple.new({4,35,'Blackbeard'}," + "{format=box.tuple.format.new({{'id','number'}," + "{'age','number'},{'name','string'}})})}" + ), + opts={"-x": "ttable"}, + ) + assert ret + assert output == ( + "+------+-------+\n" + "| id | 1 |\n" + "+------+-------+\n" + "| age | 21 |\n" + "+------+-------+\n" + "| name | Flint |\n" + "+------+-------+\n" + "+--------+---------+\n" + "| id | 2 |\n" + "+--------+---------+\n" + "| height | 187 |\n" + "+--------+---------+\n" + "| name | Sparrow |\n" + "+--------+---------+\n" + "+------+------+\n" + "| col1 | 2002 |\n" + "+------+------+\n" + "+------+--------+------------+\n" + "| id | 3 | 4 |\n" + "+------+--------+------------+\n" + "| age | 33 | 35 |\n" + "+------+--------+------------+\n" + "| name | Morgan | Blackbeard |\n" + "+------+--------+------------+\n" + "| col1 | true | |\n" + "+------+--------+------------+\n" + ) + + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_output_format_round_switching(tt_cmd, tmpdir_with_cfg): @@ -2093,36 +2435,40 @@ def test_output_format_round_switching(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="\n \\x \n\n \\x \n\n \\x \n\n \\x \n\n" + ) + assert ret + assert output == ( + "---\n" + "...\n" + "\n" + ";\n" + "+------+\n" + "| col1 |\n" + "+------+\n" + "| |\n" + "+------+\n" + "+------+--+\n" + "| col1 | |\n" + "+------+--+\n" + "---\n" + "...\n" + "\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance(tt_cmd, tmpdir, uri, - stdin="\n \\x \n\n \\x \n\n \\x \n\n \\x \n\n") - assert ret - assert output == ("---\n" - "...\n" - "\n" - ";\n" - "+------+\n" - "| col1 |\n" - "+------+\n" - "| |\n" - "+------+\n" - "+------+--+\n" - "| col1 | |\n" - "+------+--+\n" - "---\n" - "...\n" - "\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_output_format_short_named_selecting(tt_cmd, tmpdir_with_cfg): @@ -2135,37 +2481,40 @@ def test_output_format_short_named_selecting(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, uri, stdin="\n \\xl \n\n \\xt \n\n \\xT \n\n \\xy \n\n" + ) + assert ret + assert output == ( + "---\n" + "...\n" + "\n" + ";\n" + "+------+\n" + "| col1 |\n" + "+------+\n" + "| |\n" + "+------+\n" + "+------+--+\n" + "| col1 | |\n" + "+------+--+\n" + "---\n" + "...\n" + "\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin="\n \\xl \n\n \\xt \n\n \\xT \n\n \\xy \n\n") - assert ret - assert output == ("---\n" - "...\n" - "\n" - ";\n" - "+------+\n" - "| col1 |\n" - "+------+\n" - "| |\n" - "+------+\n" - "+------+--+\n" - "| col1 | |\n" - "+------+--+\n" - "---\n" - "...\n" - "\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_output_format_full_named_selecting(tt_cmd, tmpdir_with_cfg): @@ -2178,41 +2527,49 @@ def test_output_format_full_named_selecting(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "\n \\set output lua \n\n \\set output table \n\n" + " \\set output ttable \n\n \\set output yaml \n\n" + "\\set output \n" + ), + ) + assert ret + assert output == ( + "---\n" + "...\n" + "\n" + ";\n" + "+------+\n" + "| col1 |\n" + "+------+\n" + "| |\n" + "+------+\n" + "+------+--+\n" + "| col1 | |\n" + "+------+--+\n" + "---\n" + "...\n" + "\n" + " ⨯ the command expects one of: lua, table, ttable, yaml\n" + "\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("\n \\set output lua \n\n \\set output table \n\n" - " \\set output ttable \n\n \\set output yaml \n\n" - "\\set output \n")) - assert ret - assert output == ("---\n" - "...\n" - "\n" - ";\n" - "+------+\n" - "| col1 |\n" - "+------+\n" - "| |\n" - "+------+\n" - "+------+--+\n" - "| col1 | |\n" - "+------+--+\n" - "---\n" - "...\n" - "\n" - " ⨯ the command expects one of: lua, table, ttable, yaml\n" - "\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_output_format_tables_pseudo_graphic_disable(tt_cmd, tmpdir_with_cfg): @@ -2225,40 +2582,47 @@ def test_output_format_tables_pseudo_graphic_disable(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "\\xg \n \\xt \n \\xg \n" + "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000} \n" + "\\xT \n" + "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000} \n" + "\\xG \n\n" + ), + ) + assert ret + assert output == ( + " col1 col2 col3 \n" + " 10 20 30 \n" + " 40 50 60 \n" + " 70 80 \n" + " nil 1000000000 \n" + "\n" + " col1 10 40 70 nil \n" + " col2 20 50 80 1000000000 \n" + " col3 30 60 \n" + "\n" + "+------+--+\n" + "| col1 | |\n" + "+------+--+\n" + ) - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=("\\xg \n \\xt \n \\xg \n" - "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000} \n" - "\\xT \n" - "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000} \n" - "\\xG \n\n") - ) - assert ret - assert output == (" col1 col2 col3 \n" - " 10 20 30 \n" - " 40 50 60 \n" - " 70 80 \n" - " nil 1000000000 \n" - "\n" - " col1 10 40 70 nil \n" - " col2 20 50 80 1000000000 \n" - " col3 30 60 \n" - "\n" - "+------+--+\n" - "| col1 | |\n" - "+------+--+\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_output_format_tables_width_option(tt_cmd, tmpdir_with_cfg): @@ -2271,66 +2635,71 @@ def test_output_format_tables_width_option(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" - - # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] - for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=( - '\\set table_column_width 0 \n' - '{"1234567890","123456","12345","1234"},{"1234567890","123456","12345","1234"}\n' - '\\xw 5 \n' - '{"1234567890","123456","12345","1234"},{"1234567890","123456","12345","1234"}\n' - '\\xT \n' - '{"1234567890","123456","12345","1234"},{"1234567890","123456","12345","1234"}\n' - '\\xw -1\n' - '\\xy \n' - '\\set table_column_width 10 \n' - ), opts={'-x': 'table'} + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=r"""\set table_column_width 0 +{"1234567890","123456","12345","1234"},{"1234567890","123456","12345","1234"} +\xw 5 +{"1234567890","123456","12345","1234"},{"1234567890","123456","12345","1234"} +\xT +{"1234567890","123456","12345","1234"},{"1234567890","123456","12345","1234"} +\xw -1 +\xy +\set table_column_width 10 +""", + opts={"-x": "table"}, ) - assert ret - print(output) - assert output == ("+------------+--------+-------+------+\n" - "| col1 | col2 | col3 | col4 |\n" - "+------------+--------+-------+------+\n" - "| 1234567890 | 123456 | 12345 | 1234 |\n" - "+------------+--------+-------+------+\n" - "| 1234567890 | 123456 | 12345 | 1234 |\n" - "+------------+--------+-------+------+\n" - "+-------+-------+-------+------+\n" - "| col1 | col2 | col3 | col4 |\n" - "+-------+-------+-------+------+\n" - "| 12345 | 12345 | 12345 | 1234 |\n" - "| +6789 | +6 | | |\n" - "| +0 | | | |\n" - "+-------+-------+-------+------+\n" - "| 12345 | 12345 | 12345 | 1234 |\n" - "| +6789 | +6 | | |\n" - "| +0 | | | |\n" - "+-------+-------+-------+------+\n" - "+------+-------+-------+\n" - "| col1 | 12345 | 12345 |\n" - "| | +6789 | +6789 |\n" - "| | +0 | +0 |\n" - "+------+-------+-------+\n" - "| col2 | 12345 | 12345 |\n" - "| | +6 | +6 |\n" - "+------+-------+-------+\n" - "| col3 | 12345 | 12345 |\n" - "+------+-------+-------+\n" - "| col4 | 1234 | 1234 |\n" - "+------+-------+-------+\n" - " ⨯ the command expects one unsigned number\n" - "\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + assert ret + print(output) + assert output == ( + "+------------+--------+-------+------+\n" + "| col1 | col2 | col3 | col4 |\n" + "+------------+--------+-------+------+\n" + "| 1234567890 | 123456 | 12345 | 1234 |\n" + "+------------+--------+-------+------+\n" + "| 1234567890 | 123456 | 12345 | 1234 |\n" + "+------------+--------+-------+------+\n" + "+-------+-------+-------+------+\n" + "| col1 | col2 | col3 | col4 |\n" + "+-------+-------+-------+------+\n" + "| 12345 | 12345 | 12345 | 1234 |\n" + "| +6789 | +6 | | |\n" + "| +0 | | | |\n" + "+-------+-------+-------+------+\n" + "| 12345 | 12345 | 12345 | 1234 |\n" + "| +6789 | +6 | | |\n" + "| +0 | | | |\n" + "+-------+-------+-------+------+\n" + "+------+-------+-------+\n" + "| col1 | 12345 | 12345 |\n" + "| | +6789 | +6789 |\n" + "| | +0 | +0 |\n" + "+------+-------+-------+\n" + "| col2 | 12345 | 12345 |\n" + "| | +6 | +6 |\n" + "+------+-------+-------+\n" + "| col3 | 12345 | 12345 |\n" + "+------+-------+-------+\n" + "| col4 | 1234 | 1234 |\n" + "+------+-------+-------+\n" + " ⨯ the command expects one unsigned number\n" + "\n" + ) + + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_output_format_tables_dialects(tt_cmd, tmpdir_with_cfg): @@ -2343,62 +2712,69 @@ def test_output_format_tables_dialects(tt_cmd, tmpdir_with_cfg): # Start an instance. start_app(tt_cmd, tmpdir, "test_app") + try: + # Check for start. + file = wait_file(os.path.join(tmpdir, "test_app"), "ready", []) + assert file != "" - # Check for start. - file = wait_file(os.path.join(tmpdir, 'test_app'), 'ready', []) - assert file != "" - - # Connect to the instance. - uris = ["localhost:3013"] - for uri in uris: # Connect to the instance. - uris = ["localhost:3013", "tcp://localhost:3013"] + uris = ["localhost:3013"] for uri in uris: - # Execute stdin. - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, uri, - stdin=('\\xw 5 \n \\set table_format markdown \n' - '{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n' - '\\xw 0 \n' - '\\xT \n' - '{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n' - '\\set table_format jira \n' - '{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n' - '\\xt \n' - '{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n' - '\\xy \n' - '\\set table_format jira \n' - ), opts={'-x': 'table'} + # Connect to the instance. + uris = ["localhost:3013", "tcp://localhost:3013"] + for uri in uris: + # Execute stdin. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + uri, + stdin=( + "\\xw 5 \n \\set table_format markdown \n" + "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n" + "\\xw 0 \n" + "\\xT \n" + "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n" + "\\set table_format jira \n" + "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n" + "\\xt \n" + "{10,20,30}, {40,50,60}, {70, 80}, {box.NULL, 1000000000}\n" + "\\xy \n" + "\\set table_format jira \n" + ), + opts={"-x": "table"}, ) - assert ret - print(output) - assert output == ("| | | |\n" - "|-|-|-|\n" - "| col1 | col2 | col3 |\n" - "| 10 | 20 | 30 |\n" - "| 40 | 50 | 60 |\n" - "| 70 | 80 | |\n" - "| nil | 10000+0000+0 | |\n" - "\n" - "| | | | | |\n" - "|-|-|-|-|-|\n" - "| col1 | 10 | 40 | 70 | nil |\n" - "| col2 | 20 | 50 | 80 | 1000000000 |\n" - "| col3 | 30 | 60 | | |\n" - "\n" - "| col1 | 10 | 40 | 70 | nil |\n" - "| col2 | 20 | 50 | 80 | 1000000000 |\n" - "| col3 | 30 | 60 | | |\n" - "\n" - "| col1 | col2 | col3 |\n" - "| 10 | 20 | 30 |\n" - "| 40 | 50 | 60 |\n" - "| 70 | 80 | |\n" - "| nil | 1000000000 | |\n" - "\n") - - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + assert ret + print(output) + assert output == ( + "| | | |\n" + "|-|-|-|\n" + "| col1 | col2 | col3 |\n" + "| 10 | 20 | 30 |\n" + "| 40 | 50 | 60 |\n" + "| 70 | 80 | |\n" + "| nil | 10000+0000+0 | |\n" + "\n" + "| | | | | |\n" + "|-|-|-|-|-|\n" + "| col1 | 10 | 40 | 70 | nil |\n" + "| col2 | 20 | 50 | 80 | 1000000000 |\n" + "| col3 | 30 | 60 | | |\n" + "\n" + "| col1 | 10 | 40 | 70 | nil |\n" + "| col2 | 20 | 50 | 80 | 1000000000 |\n" + "| col3 | 30 | 60 | | |\n" + "\n" + "| col1 | col2 | col3 |\n" + "| 10 | 20 | 30 |\n" + "| 40 | 50 | 60 |\n" + "| 70 | 80 | |\n" + "| nil | 1000000000 | |\n" + "\n" + ) + + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app") def test_connect_to_single_instance_app_binary(tt_cmd): @@ -2678,35 +3054,37 @@ def test_set_delimiter( # Start an instance. start_app(tt_cmd, tmpdir, "test_app") - # Check for start. - file = wait_file(tmpdir / "test_app" / ready_file.parent, ready_file.name, []) - assert file != "" + try: + # Check for start. + file = wait_file(tmpdir / "test_app" / ready_file.parent, ready_file.name, []) + assert file != "" - # Without delimiter should get an error. - ret, output = try_execute_on_instance( - tt_cmd, - tmpdir, - instance, - opts=opts, - stdin=input, - ) - assert ret - assert "attempt to perform arithmetic on global" in output + # Without delimiter should get an error. + ret, output = try_execute_on_instance( + tt_cmd, + tmpdir, + instance, + opts=opts, + stdin=input, + ) + assert ret + assert "attempt to perform arithmetic on global" in output - # With delimiter expecting correct responses. - input = f"\\set delimiter {delimiter}\n{input}{delimiter}\n" - ret, output = try_execute_on_instance( - tt_cmd, tmpdir, instance, opts=opts, stdin=input - ) - assert ret - assert ( - output - == """--- + # With delimiter expecting correct responses. + input = f"\\set delimiter {delimiter}\n{input}{delimiter}\n" + ret, output = try_execute_on_instance( + tt_cmd, tmpdir, instance, opts=opts, stdin=input + ) + assert ret + assert ( + output + == """--- - 2 ... """ - ) + ) - # Stop the Instance. - stop_app(tt_cmd, tmpdir, "test_app") + finally: + # Stop the Instance. + stop_app(tt_cmd, tmpdir, "test_app")