@@ -32,6 +32,43 @@ def test_valid_args(filepath):
3232 assert sqlparse .cli .main ([path , '-r' ]) is not None
3333
3434
35+ def test_invalid_choise (filepath ):
36+ path = filepath ('function.sql' )
37+ with pytest .raises (SystemExit ):
38+ sqlparse .cli .main ([path , '-l' , 'spanish' ])
39+
40+
41+ def test_invalid_args (filepath , capsys ):
42+ path = filepath ('function.sql' )
43+ sqlparse .cli .main ([path , '-r' , '--indent_width' , '0' ])
44+ _ , err = capsys .readouterr ()
45+ assert err == ("[ERROR] Invalid options: indent_width requires "
46+ "a positive integer\n " )
47+
48+
49+ def test_invalid_infile (filepath , capsys ):
50+ path = filepath ('missing.sql' )
51+ sqlparse .cli .main ([path , '-r' ])
52+ _ , err = capsys .readouterr ()
53+ assert err [:22 ] == "[ERROR] Failed to read"
54+
55+
56+ def test_invalid_outfile (filepath , capsys ):
57+ path = filepath ('function.sql' )
58+ outpath = filepath ('/missing/function.sql' )
59+ sqlparse .cli .main ([path , '-r' , '-o' , outpath ])
60+ _ , err = capsys .readouterr ()
61+ assert err [:22 ] == "[ERROR] Failed to open"
62+
63+
64+ def test_stdout (filepath , load_file , capsys ):
65+ path = filepath ('begintag.sql' )
66+ expected = load_file ('begintag.sql' )
67+ sqlparse .cli .main ([path ])
68+ out , _ = capsys .readouterr ()
69+ assert out == expected
70+
71+
3572def test_script ():
3673 # Call with the --help option as a basic sanity check.
3774 cmd = "{0:s} -m sqlparse.cli --help" .format (sys .executable )
0 commit comments