Question: When I run the code for part 2 it says FAILED (errors=1) I don't have any issue with part 1 as my code works good

When I run the code for part 2 it says FAILED (errors=1) I don't have any issue with part 1 as my code works good for part 1 with the text file (my_poem.txt).

Course: Applied OO Programming.

Here is the question:

Write program that performs the actions described in Parts 1 and 2

Part 1 : Write a program (homework_part1.py) that prompts the user to enter the name of a file (example: my_poem.txt) containing lines of text. The program will perform the following actions:

1. Display the contents of the file as a list

2. Search for and display all words that begin with a vowel

Include the following in your program logic

1. A function, read_file, that opens and reads the content of the file into a list. read_file function takes the name of the file as a parameter. It reads the contents of the file into a list and returns the list

2. A function, vowel_words, that takes the list containing the contents of the file and returns a list containing words that begin with a vowel

My code don't work in Part 2

Write a test case module (unittest_vowel_words.py) for the vowel_words function. The module will include the following:

1. Import the module for Part1 (homework_part1) .

2. Test case class that tests the vowel_words function. The class will include a test method, test_vowel_words

3. Logic in the test_vowel_words method for testing/validating the vowel_words function

4. Main logic that executes the test case

Part 1 Example output:

Enter the name of a file: my_poem.txt

Two roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood And looked down one as far as I could To where it bent in the undergrowth;

Then took the other, as just as fair, And having perhaps the better claim. Because it was grassy and wanted wear, Though as for that the passing there. Had worn them really about the same,

Words that begins with vowel

['in', 'a', 'And', 'I', 'And', 'one', 'I', 'And', 'one', 'as', 'I', 'it', 'in', 'undergrowth', 'other', 'as', 'And', 'it', 'and', 'as', 'about', 'And', 'equally', 'In', 'oh,', 'I', 'another', 'on', 'I', 'if', 'I', 'ever', 'I', 'a', 'ages', 'and', 'ages', 'in', 'a', 'and', 'I,', 'I', 'one', 'And', 'all']

Part Two Example Output:

test_data = ['Two roads diverged in a yellow wood','And looked down one as far as I could','I doubted if I should ever come back']

expected_result = ['in',' 'a',' 'And',' 'one',' 'as',' 'as', 'I',' 'I', 'if', 'I', 'ever']

Here is my code for part 2. I'm not sure what I am doing wrong that my code display FAILED (errors=1) when I run it. Please help and explain in details the possible solution for this issue, and thanks for your help.

import unittest import homework_part1

class TestVowelWords(unittest.TestCase): def test_vowel_words(self): file_content = homework_part1.read_file('my_poem.txt') vowel_words_list = homework_part1.vowel_words(file_list) expected_output = ['a', 'is', 'also', 'a', 'as', 'ome', 'ords', 'tarting', 'ith', 'owels.', 'also', 'as', 'ome', 'ords', 'tarting', 'ith', 'onsonants.'] self.assertEqual(homework_part1.vowel_words(file_content), expected_output)

file_content = [] expected_output = [] self.assertEqual(homework_part1.vowel_words(file_content), expected_output) if __name__ == '__main__': unittest.main()

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!