4
4
import shutil
5
5
import subprocess
6
6
import tempfile
7
+ from pathlib import Path
7
8
8
9
import psutil
9
10
import pytest
@@ -233,6 +234,7 @@ def test_connect_and_get_commands_outputs(tt_cmd, tmpdir_with_cfg):
233
234
\\ set table_format <format> -- set table format default, jira or markdown
234
235
\\ set graphics <false/true> -- disables/enables pseudographics for table modes
235
236
\\ set table_column_width <width> -- set max column width for table/ttable
237
+ \\ set delimiter <marker> -- set expression delimiter
236
238
\\ xw <width> -- set max column width for table/ttable
237
239
\\ x -- switches output format cyclically
238
240
\\ x[l,t,T,y] -- set output format lua, table, ttable or yaml
@@ -253,6 +255,8 @@ def test_connect_and_get_commands_outputs(tt_cmd, tmpdir_with_cfg):
253
255
commands ["\\ set graphics false" ] = ""
254
256
commands ["\\ set graphics true" ] = ""
255
257
commands ["\\ set table_column_width 1" ] = ""
258
+ commands ["\\ set delimiter ;" ] = ""
259
+ commands ["\\ set delimiter" ] = ""
256
260
commands ["\\ xw 1" ] = ""
257
261
commands ["\\ x" ] = ""
258
262
commands ["\\ xl" ] = ""
@@ -331,6 +335,7 @@ def test_connect_and_get_commands_errors(tt_cmd, tmpdir_with_cfg):
331
335
commands ["\\ set graphics arg" ] = "⨯ the command expects one boolean"
332
336
commands ["\\ set table_column_width" ] = "⨯ the command expects one unsigned number"
333
337
commands ["\\ set table_column_width arg" ] = "⨯ the command expects one unsigned number"
338
+ commands ["\\ set delimiter arg arg" ] = "⨯ the command expects zero or single argument"
334
339
commands ["\\ xw" ] = "⨯ the command expects one unsigned number"
335
340
commands ["\\ xw arg" ] = "⨯ the command expects one unsigned number"
336
341
commands ["\\ x arg" ] = "⨯ the command does not expect arguments"
@@ -2595,3 +2600,65 @@ def test_connect_to_cluster_app(tt_cmd):
2595
2600
# Stop the Instance.
2596
2601
stop_app (tt_cmd , tmpdir , app_name )
2597
2602
shutil .rmtree (tmpdir )
2603
+
2604
+
2605
+ @pytest .mark .parametrize (
2606
+ "instance, opts, ready_file" ,
2607
+ (
2608
+ ("test_app" , None , Path (run_path , "test_app" , control_socket )),
2609
+ (
2610
+ "localhost:3013" ,
2611
+ {"-u" : "test" , "-p" : "password" },
2612
+ Path ("ready" ),
2613
+ ),
2614
+ ),
2615
+ )
2616
+ def test_set_delimiter (
2617
+ tt_cmd , tmpdir_with_cfg , instance : str , opts : None | dict , ready_file : Path
2618
+ ):
2619
+ input = """local a=1
2620
+ a = a + 1
2621
+ return a
2622
+ """
2623
+ delimiter = "</br>"
2624
+ tmpdir = Path (tmpdir_with_cfg )
2625
+
2626
+ # The test application file.
2627
+ test_app_path = Path (__file__ ).parent / "test_localhost_app" / "test_app.lua"
2628
+ # Copy test data into temporary directory.
2629
+ copy_data (tmpdir , [test_app_path ])
2630
+
2631
+ # Start an instance.
2632
+ start_app (tt_cmd , tmpdir , "test_app" )
2633
+ # Check for start.
2634
+ file = wait_file (tmpdir / "test_app" / ready_file .parent , ready_file .name , [])
2635
+ assert file != ""
2636
+
2637
+ # Without delimiter should get an error.
2638
+ ret , output = try_execute_on_instance (
2639
+ tt_cmd ,
2640
+ tmpdir ,
2641
+ instance ,
2642
+ opts = opts ,
2643
+ stdin = input ,
2644
+ )
2645
+ assert ret
2646
+ assert "attempt to perform arithmetic on global" in output
2647
+
2648
+ # With delimiter expecting correct responses.
2649
+ input = f"\\ set delimiter { delimiter } \n { input } { delimiter } \n "
2650
+ ret , output = try_execute_on_instance (
2651
+ tt_cmd , tmpdir , instance , opts = opts , stdin = input
2652
+ )
2653
+ assert ret
2654
+ assert (
2655
+ output
2656
+ == """---
2657
+ - 2
2658
+ ...
2659
+
2660
+ """
2661
+ )
2662
+
2663
+ # Stop the Instance.
2664
+ stop_app (tt_cmd , tmpdir , "test_app" )
0 commit comments