P2 Task 2 Unit Testing Using Modules In The Previous Task Each Team Member Has Implemented Two Functionalities Add Rem 1 (270.13 KiB) Viewed 47 times
P2 Task 2: Unit Testing Using Modules In the previous task, each team member has implemented two functionalities add/remove data from the datasets or search for data. In this task, you will use modules to develop the automated unit tests for your functions. You need to test each function individually as explained in the lecture “Unit testing”. The test harness will be developed before the function is implemented. Remember to use automated testing as you learn in ECOR1041. Do not worry about the print statements in your tests, just focus on the returned value of the function. For your tests, it would be a good idea to use a smaller data set. You can manually create dictionaries for your “test data set or you can create test_xxx.csv files that you load using the function developed in P1. In the latter case, remember to import the module developed in P1, so your lab runs without errors.
import string from typing import List def get_books_by_publisher ( file_name : str, publisher_name : str) -> int: OVOU AWNA 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 infile = open(file_name, 'r') file_name = OL publisher_nameb = list(publisher_name) publisher_title_list = [] publisher_author_list = [] publishers_books = 0 j = 1 for i in infile: i = i.split(",") if i[3] == publisher_name: publisher_title_list.append(i[@]) publisher_author_dict.append(i[1]) publishers_books = publisher_books + 1 else: print('no books published by that publisher are in this book library') print('the publisher', publisher_name, ' has published the following books:') for x in range(len(publisher_title_list)): print('book', X+1, , publisher_title_list[x], by", publisher_author_list[x], "") return publisher_books 11 1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!