File tree 6 files changed +91
-0
lines changed
troubleshooting_car_issues
6 files changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ def print_header ():
4
+ """ Print header
5
+ """
6
+ header_text = ''
7
+ TEXT = f' Troubleshooting car issues \n '
8
+ line = '-' * len (TEXT )
9
+ line += '\n '
10
+
11
+ header_text += line
12
+ header_text += TEXT
13
+ header_text += line
14
+ print (header_text )
15
+
16
+
17
+ def get_yes_or_no (question ):
18
+
19
+ while True :
20
+ answer = input (question )
21
+ answer = answer .lower ()
22
+ if answer == 'y' or answer == 'yes' :
23
+ return True
24
+ elif answer == 'n' or answer == 'no' :
25
+ return False
26
+ else :
27
+ print ('A valid input is required' )
28
+
29
+
30
+
31
+ def print_answer (answer ):
32
+ print (answer )
33
+
34
+
35
+ if __name__ == "__main__" :
36
+
37
+ print_header ()
38
+ if get_yes_or_no ('Is the car silent when you turn the key? ' ):
39
+ if get_yes_or_no ('Are the battery terminals corroded? ' ):
40
+ print ('Clean terminals and try starting again' )
41
+ else :
42
+ print ('Replace cables and try again' )
43
+ else :
44
+ if get_yes_or_no ('Does the car make a clicking noise? ' ):
45
+ print ('Replace the battery' )
46
+ else :
47
+ if get_yes_or_no ('Does the car crank up but fail to start? ' ):
48
+ print ('Check spark blug connections' )
49
+ else :
50
+ if get_yes_or_no ('Does the engine start and then die? ' ):
51
+ if get_yes_or_no ('Does your car have fuel injection? ' ):
52
+ print ('Ge it in for service' )
53
+ else :
54
+ print ('Check to ensure the choke is opening and closing' )
55
+
Original file line number Diff line number Diff line change
1
+ from unittest import TestCase
2
+ from unittest .mock import patch
3
+ import app
4
+
5
+ class AppTest (TestCase ):
6
+
7
+ def test_print_header (self ):
8
+
9
+ expected = '-----------------------------\n Troubleshooting car issues \n -----------------------------\n '
10
+ with patch ('builtins.print' ) as mocked_print :
11
+ app .print_header ()
12
+ mocked_print .assert_called_with (expected )
13
+
14
+ def test_get_get_yes_or_no (self ):
15
+ expected = False
16
+ expected_input = 'Is the car silent when you turn the key? '
17
+ question = expected_input
18
+ with patch ('builtins.input' ) as mocked_input :
19
+ with patch ('builtins.print' ) as mocked_print :
20
+ mocked_input .side_effect = ('' , 'y' , 'n' )
21
+ answer = app .get_yes_or_no (question )
22
+ mocked_print .assert_called_with ('A valid input is required' )
23
+ mocked_input .assert_called_with (expected_input )
24
+ self .assertEqual (answer , not expected )
25
+ answer = app .get_yes_or_no (question )
26
+ self .assertEqual (answer , expected )
Original file line number Diff line number Diff line change
1
+ from unittest import TestCase
2
+ import app
3
+
4
+ class ComparingNumbersTest (TestCase ):
5
+ pass
6
+ # def test_get_month_from_number(self):
7
+ # month_number = 3
8
+ # expected_month = 'March'
9
+ # month = app.get_month_from_number(month_number)
10
+ # self.assertEqual(month, expected_month)
You can’t perform that action at this time.
0 commit comments