Question: Assignment 3 : Python Benchmarking, Logging, and Unit Testing Purpose : Practice using Python benchmarking, logging, and unit testing . Grades will start at 100%

Assignment 3: Python Benchmarking, Logging, and Unit Testing

Purpose: Practice using Python benchmarking, logging, and unit testing.

Grades will start at 100% and then deductions made for errors preventing the correct answer to be calculated, or if the solution does not use Python classes, inheritance and overloading.

Individual Assignment: Hand-In your own Python source code (submit to Assignment object in Moodle). Feel free to collaborate in your groups, but dont copy the groups solution. Copied solutions (both originator and user) will receive a grade of 0.

Due in 2 weeks (allows us to resolve any doubts during the following class).

Name your zip file: [your name]+[your ID]+assignment 3.zip

Use only standard Python libraries (i.e. timeit, logging, unittest, etc. and native Python code) to solve.

Assignment code files will be file-compared with the class. Identical or nearly identical submissions will both receive 0.

Problem:

Revisit your Assignment 2 (if you need Assignment 2 code let me know) and:

Instrument your code by benchmarking to time the duration of long calculations and then both display them to console output and log them in a logfile
Log events (at least 1 from each of the classes Info, Warning, Error, Exception) to a log file
In a separate sub-package named test, add unit tests that run as a separate target in your project, and use at least 1 of each class: AssertEqual or AssertNotEqual, AssertTrue or AssertFalse, AssertIsor AssertIsNot, AssertIsNone or AssertIsNotNone, AssertIn or AssertNotIn, assertIsInstance or assertIsNotInstance, assertRaises, and assertGreateror assertLess, and any other assert method you would like to use as a unit test

Example Code Snippet (doesnt run, has defects but outlines an approach, provided as a starting point, feel free to modify, improve and create your approach)

from unittest import TestCase

import DirectedEdge

class TestDirectedEdge(TestCase):

def setUp(self):

self.directed_edge0 = DirectedEdge.DirectedEdge('A', 1)

got_expected_assertion = False

try:

self.directed_edge1 = DirectedEdge.DirectedEdge('B', 0)

except AssertionError as e:

got_expected_assertion = True

if not got_expected_assertion:

self.fail()

.

def test_get_to_vertex(self):

self.assertGreater(len(self.directed_edge0.get_to_vertex()), 0)

self.assertGreater(len(self.directed_edge3.get_to_vertex()), 0)

.

class TestProblem(TestCase):

def setUp(self):

directed_graph = DirectedGraph.DirectedGraph()

got_expected_assertion = False

try:

Problem.Problem(-1, directed_graph)

except AssertionError as e:

got_expected_assertion = True

if not got_expected_assertion:

self.fail()

got_expected_assertion = False

try:

Problem.Problem(1, directed_graph)

except AssertionError as e:

got_expected_assertion = True

if not got_expected_assertion:

self.fail()

Rectify the errors and run the code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!