1+ import pytest
2+
13from shellwhat .State import State
24from protowhat .Reporter import Reporter
35from protowhat .Test import TestFail as TF
46from protowhat .checks .check_funcs import check_node , check_edge , has_equal_ast
7+ from shellwhat .parsers import OshParser
58
6- import pytest
9+
10+ @pytest .fixture (autouse = True )
11+ def run_around_tests ():
12+ yield
13+ OshParser .nodes = {}
714
815
916@pytest .fixture ("function" )
1017def state ():
11- return State (
18+ state = State (
1219 student_code = "echo a $b ${c}" ,
1320 solution_code = "echo a $b ${c} unique" ,
1421 pre_exercise_code = "" ,
@@ -18,16 +25,65 @@ def state():
1825 solution_result = "" ,
1926 reporter = Reporter (),
2027 )
28+ state .root_state = state
29+ return state
2130
2231
2332@pytest .fixture ("function" )
2433def d ():
2534 return state ().get_dispatcher ()
2635
2736
37+ @pytest .fixture ("function" )
38+ def shell_script ():
39+ return """# Use curl, download file from URL and rename
40+ curl -o Spotify201812.zip -L https://tinyurl.com/Zipped201812Spotify
41+
42+ # Unzip file then delete original zipped file
43+ unzip Spotify201812.zip && rm Spotify201812.zip
44+
45+ # View url_list.txt to verify content
46+ cat url_list.txt
47+
48+ # Use wget, download all files in url_list.txt
49+ wget -i url_list.txt
50+
51+ # Take a look at all files downloaded
52+ ls"""
53+
54+
2855@pytest .mark .osh
2956class TestOsh :
3057 # TODO: check top node?
58+ def test_osh_parsing (self , d , shell_script ):
59+ d .ast_mod .parse (shell_script )
60+
61+ def test_sct (self , shell_script ):
62+ from shellwhat .test_exercise import test_exercise as te
63+
64+ sct_payload = te (
65+ """
66+ Ex().check_node('SimpleCommand', 0).multi(
67+ check_edge('words', 0).has_equal_ast(),
68+ check_edge('words', 1).has_equal_ast(),
69+ check_edge('words', 2).has_equal_ast(),
70+ check_edge('words', 3).has_equal_ast(),
71+ check_edge('words', 4).has_equal_ast()
72+ )""" ,
73+ student_code = shell_script ,
74+ solution_code = shell_script ,
75+ pre_exercise_code = """from urllib.request import urlretrieve
76+ url = 'https://assets.datacamp.com/production/repositories/4180/datasets/b4e48732f25e87864f6ce23066b8c0d14c7c6430/Chp1Capstone_urlList.txt'
77+ urlretrieve(url, 'url_list.txt')""" ,
78+ student_conn = None ,
79+ solution_conn = None ,
80+ student_result = "" ,
81+ solution_result = "" ,
82+ ex_type = "NormalExercise" ,
83+ error = [],
84+ )
85+ assert sct_payload .get ("correct" )
86+
3187 def test_osh_dispatcher_ast_fails_hard (self , d ):
3288 with pytest .raises (d .ParseError ):
3389 d .ast_mod .parse ("for ii" )
@@ -54,6 +110,12 @@ def test_osh_selector_high_priority(self, state):
54110 child = check_node (state , "BracedVarSub" , priority = 99 )
55111 assert isinstance (child .student_ast , target )
56112 assert child .student_ast .token .val == "c"
113+ with pytest .raises (TF ):
114+ from protowhat .Feedback import Feedback
115+
116+ fb = Feedback ("test" )
117+ child .report (fb )
118+ assert fb .highlight is not None
57119
58120 def test_osh_selector_fail (self , state ):
59121 with pytest .raises (TF ):
0 commit comments