11import importlib .metadata
2+ import os
23import re
34import shlex
45import subprocess
56import sys
67import time
78from importlib import resources as rso
89
10+ import pytest
911from click .testing import CliRunner
1012
1113from asciinema_scene .sciine import cli
2123
2224
2325def my_invoke (command : str , input_content : str ):
24- cmd = "sciine " + command
2526 if sys .platform == "win32" :
26- args = cmd
27+ args = [ command ]
2728 else :
28- args = shlex .split (cmd )
29+ args = shlex .split (command )
30+ sciine_executable = os .path .join (sys .prefix , "bin" , "sciine" )
31+ coverage_command_prefix = [
32+ sys .executable ,
33+ "-m" ,
34+ "coverage" ,
35+ "run" ,
36+ sciine_executable ,
37+ ]
38+ # full_command_args = shlex.split(command)
39+ cmd_to_execute = coverage_command_prefix + args
40+ env = os .environ .copy ()
2941 proc = subprocess .Popen (
30- args ,
42+ cmd_to_execute ,
3143 stdin = subprocess .PIPE ,
3244 stdout = subprocess .PIPE ,
45+ env = env ,
3346 )
3447 proc .stdin .write (input_content .encode ())
3548 proc .stdin .close ()
@@ -71,6 +84,7 @@ def test_cli_help():
7184 assert re .search (text , result .output ) is not None
7285
7386
87+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
7488def test_cli_cut ():
7589 code , output = my_invoke ("cut -e 3.0" , SHORT_FILE_CONTENT )
7690 assert code == 0
@@ -79,6 +93,7 @@ def test_cli_cut():
7993 assert "Duration: 3.023" in output2
8094
8195
96+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
8297def test_cli_copy ():
8398 code , output = my_invoke ("copy -e 1.0" , SHORT_FILE_CONTENT )
8499 assert code == 0
@@ -87,12 +102,14 @@ def test_cli_copy():
87102 assert "Duration: 1.163" in output2
88103
89104
105+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
90106def test_cli_header ():
91107 code , output = my_invoke ("header" , SHORT_FILE_CONTENT )
92108 assert code == 0
93109 assert "/bin/bash" in output
94110
95111
112+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
96113def test_cli_include ():
97114 code = output = None
98115 for file in rso .files ("tests.files" ).iterdir ():
@@ -109,6 +126,7 @@ def test_cli_include():
109126 assert "Duration: 12.271986" in output2
110127
111128
129+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
112130def test_cli_insert ():
113131 code , output = my_invoke ("insert 1.0 5.0 message" , SHORT_FILE_CONTENT )
114132 assert code == 0
@@ -117,6 +135,7 @@ def test_cli_insert():
117135 assert "Duration: 11.135993" in output2
118136
119137
138+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
120139def test_cli_delete ():
121140 code , output = my_invoke ("delete 1.16" , SHORT_FILE_CONTENT )
122141 assert code == 0
@@ -125,6 +144,7 @@ def test_cli_delete():
125144 assert "Duration: 5.835392" in output2
126145
127146
147+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
128148def test_cli_replace ():
129149 code , output = my_invoke ("replace 1.16 abc" , SHORT_FILE_CONTENT )
130150 assert code == 0
@@ -136,6 +156,7 @@ def test_cli_replace():
136156 assert "abc" in output3 .strip ()
137157
138158
159+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
139160def test_cli_insert_o ():
140161 code , output = my_invoke ("insert 1.0 5.0 message o" , SHORT_FILE_CONTENT )
141162 assert code == 0
@@ -144,6 +165,7 @@ def test_cli_insert_o():
144165 assert "Duration: 11.135993" in output2
145166
146167
168+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
147169def test_cli_maximum ():
148170 code , output = my_invoke ("maximum 0.1" , SHORT_FILE_CONTENT )
149171 assert code == 0
@@ -152,6 +174,7 @@ def test_cli_maximum():
152174 assert "Duration: 2.000" in output2
153175
154176
177+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
155178def test_cli_minimum ():
156179 code , output = my_invoke ("minimum 10.0" , SHORT_FILE_CONTENT )
157180 assert code == 0
@@ -160,6 +183,7 @@ def test_cli_minimum():
160183 assert "Duration: 210.000" in output2
161184
162185
186+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
163187def test_cli_quantize ():
164188 code , output = my_invoke ("quantize 0.1 3.0 20.0" , SHORT_FILE_CONTENT )
165189 assert code == 0
@@ -168,57 +192,66 @@ def test_cli_quantize():
168192 assert "Duration: 400.000" in output2
169193
170194
195+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
171196def test_cli_show_1 ():
172197 code , output = my_invoke ("show" , SHORT_FILE_CONTENT )
173198 assert code == 0
174199 assert f"0.000│ 0.89│ 'e'{ CR } " in output
175200
176201
202+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
177203def test_cli_show_2 ():
178204 code , output = my_invoke ("show --precise" , SHORT_FILE_CONTENT )
179205 assert code == 0
180206 assert f"0.000000│ 0.894038│ 'e'{ CR } " in output
181207
182208
209+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
183210def test_cli_show_3 ():
184211 code , output = my_invoke ("show --text" , SHORT_FILE_CONTENT )
185212 assert code == 0
186213 assert "0.000│ 0.89│ e" in output
187214
188215
216+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
189217def test_cli_show_4 ():
190218 code , output = my_invoke ("show --text --precise" , SHORT_FILE_CONTENT )
191219 assert code == 0
192220 assert f"0.000000│ 0.894038│ e{ CR } " in output
193221
194222
223+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
195224def test_cli_show_5 ():
196225 code , output = my_invoke ("show --lines 2" , SHORT_FILE_CONTENT )
197226 assert code == 0
198227 assert f"0.000│ 0.89│ 'e'{ CR } " in output
199228
200229
230+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
201231def test_cli_show_6 ():
202232 code , output = my_invoke ("show -s 0.0" , SHORT_FILE_CONTENT )
203233 assert code == 0
204234 assert f"0.000│ 0.89│ 'e'{ CR } " in output
205235 assert len (output .strip ().split (CR )) == 22
206236
207237
238+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
208239def test_cli_show_7 ():
209240 code , output = my_invoke ("show -s 1.0" , SHORT_FILE_CONTENT )
210241 assert code == 0
211242 assert f"0.000│ 0.89│ 'e'{ CR } " not in output
212243 assert len (output .strip ().split (CR )) == 19
213244
214245
246+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
215247def test_cli_show_8 ():
216248 code , output = my_invoke ("show -s 1.0 -e 2.0" , SHORT_FILE_CONTENT )
217249 assert code == 0
218250 assert f"0.000│ 0.89│ 'e'{ CR } " not in output
219251 assert len (output .strip ().split (CR )) == 3
220252
221253
254+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
222255def test_cli_speed ():
223256 code , output = my_invoke ("speed 1.0" , SHORT_FILE_CONTENT )
224257 assert code == 0
@@ -228,6 +261,7 @@ def test_cli_speed():
228261 assert "Duration: 6.135993" in output2
229262
230263
264+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
231265def test_cli_text_delete ():
232266 code , output = my_invoke ("text-delete -s 1.0 {server}" , BACK_FILE_CONTENT )
233267 assert code == 0
@@ -237,6 +271,7 @@ def test_cli_text_delete():
237271 assert "Frames: 6" in output2
238272
239273
274+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
240275def test_cli_text_replace ():
241276 code , output = my_invoke ("text-replace -s 1.0 {server} box" , BACK_FILE_CONTENT )
242277 assert code == 0
@@ -245,25 +280,39 @@ def test_cli_text_replace():
245280 assert result_cast .count ("box" ) == 19
246281
247282
283+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
248284def test_cli_text_merge ():
249285 code , output = my_invoke ("text-merge nothing" , BACK_FILE_CONTENT )
250286 assert code == 0
251287 result_cast = output
252288 assert result_cast .count ("server" ) == 25
253289
254290
291+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
255292def test_cli_status ():
256293 code , output = my_invoke ("status" , SHORT_FILE_CONTENT )
257294 assert code == 0
258295 assert "Duration: 6.135993" in output
259296
260297
298+ @pytest .mark .skipif (sys .platform == "win32" , reason = "not for windows" )
261299def test_timeout ():
262- command = "status"
300+ sciine_executable = os .path .join (sys .prefix , "bin" , "sciine" )
301+ coverage_command_prefix = [
302+ sys .executable ,
303+ "-m" ,
304+ "coverage" ,
305+ "run" ,
306+ sciine_executable ,
307+ ]
308+ cmd_to_execute = coverage_command_prefix
309+ cmd_to_execute .append ("status" )
310+ env = os .environ .copy ()
263311 proc = subprocess .Popen (
264- shlex . split ( "sciine " + command ) ,
312+ cmd_to_execute ,
265313 stdin = subprocess .PIPE ,
266314 stdout = subprocess .PIPE ,
315+ env = env ,
267316 )
268317 time .sleep (2 )
269318 proc .stdin .close ()
0 commit comments