Write file that will import the modules unittest


This assignment is intended to give you practice with mock objects. You're going to write test cases for code that is supposed to operate on files packaged together. The files will be stored in compressed form, inside a zipfile which can be extracted by Python's zipfile module.

1. You are given some existing code in "bb.py". The runTest() method is deliberately undefined. Do not edit "bb.py"
2. You need to write hw3_test.py that will import the modules unittest, unittest.mock, zipfile and bb and/or parts of these modules
3. You will be mocking the following:

  • The runTest() method
  • The zipfile passed into the constructor for BBSubmission
  • This zipfile's namelist() function - you will decide what the list of filenames (strings) it should return should be

One approach is to

  • import bb

and to replace bb.BBSubmission.runTest and then create mock objects for the zipfile object and then that mock object's namelist field.

4. The test cases you need to write in "hw3_test.py" are as follows:

  • Case where findFile is called and the file is found. You can use regular assertions here as long as you mock the namelist function correctly
  • Case where findFile is called and the file is not found.
  • Case where testSubmission() is called and everything is ok - all required files are found in the zipfile, so the code should reach the call to runTest. Checking if this case is ok means:
  1. Checking if the zipfile object's extract() function was called with each of the file names (the test file and all of the src files - there should be at least one src file). Note that you will want to use assert_any_call because assert_called_with only checks the most recent call
  2. Checking if runTest has been called with the test filename
  • Case where testSubmission() is called and one of the files was not found. You need to check
  1. That a FileNotFoundError was raised
  2. That runTest was not called

Attachment:- bb.rar

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Write file that will import the modules unittest
Reference No:- TGS02645109

Expected delivery within 24 Hours