Skip to content

Commit 8f5e4f1

Browse files
author
Ishaq Khan
committed
debugging
1 parent 4952249 commit 8f5e4f1

8 files changed

+68
-0
lines changed

Diff for: __pycache__/logging.cpython-38.pyc

258 Bytes
Binary file not shown.

Diff for: __pycache__/logging.cpython-39.pyc

258 Bytes
Binary file not shown.

Diff for: assert.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
market_2nd = {'north': 'green' , 'south' : 'red'}
2+
3+
def switchLights(intersection):
4+
for key in intersection.keys():
5+
if intersection[key] == 'green':
6+
intersection[key] = 'yellow'
7+
elif intersection[key] == 'yellow':
8+
intersection[key] = 'red'
9+
elif intersection[key] == 'red':
10+
intersection[key] == 'green'
11+
assert 'red' in intersection.values(), 'neither light is red!' + str(intersection)
12+
13+
switchLights(market_2nd)

Diff for: factorial.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import logging #logging module
2+
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s - %(levelname)s - %(message)s')
3+
logging.debug('Start of debugger')
4+
5+
def factorial(n):
6+
total = 1
7+
for i in range(1, n+ 1):
8+
total *= i
9+
return total
10+
factorial(10)
11+
12+
print('hello')

Diff for: logging.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logging #logging module
2+
3+
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s - %(levelname)s - %(message)s')
4+
5+

Diff for: mockData/error_log.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Traceback (most recent call last):
2+
File "<stdin>", line 2, in <module>
3+
Exception: this is the error message

Diff for: printBox.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#finding the bugs
2+
#own custom message
3+
#raise Exception('this is a custom message')
4+
5+
def boxPrint(symbol, width, height):
6+
if len(symbol) != 1:
7+
raise Exception('Needs to be a string of length 1')
8+
if (width < 2) or (height < 2):
9+
raise Exception('width and height have to greater than 1')
10+
print(symbol * width)
11+
12+
for i in range(height - 2):
13+
print(symbol + (' ' * (width - 2)) + symbol )
14+
15+
print(symbol * width)
16+
17+
18+
boxPrint('*', 20, 20)
19+
boxPrint (')' , 20, 2 )
20+

Diff for: writingAnError.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#change the directory to mockData folder
2+
import os
3+
os.chdir(os.getcwd() + '\\mockData')
4+
os.getcwd()
5+
#recording the error message
6+
import traceback
7+
try:
8+
raise Exception('this is the error message')
9+
except:
10+
errorFile = open('error_log.txt', 'a')
11+
errorFile.write(traceback.format_exc()) #appends the error message to the log
12+
errorFile.close()
13+
14+
#Assertion is an insanity check is the check fails, raise an exception
15+
assert False, 'this is the error message' #if asserts to fault print error message

0 commit comments

Comments
 (0)