Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Test Case Assertion Error
#3
ichabod801 - ok, I understand what you are saying. But, I am still trying to figure out if the discover is supposed to be as def discover_path(self), then how do I get it to recognize the self._src as path? The code is supposed to be written to accept any website, file, or text listed below. But I found if I used an if/else it gave me an error. Thank you for your help! It is greatly appreciated!

Here is the snipit of the code where this starts:
import requests, re
from bs4 import BeautifulSoup
from collections import Counter
import statistics as stats
import string
import operator
import matplotlib.pyplot as plt
plt.rcdefaults()

class TextAnalyzer():
    "A Text Analyzer"
    def __init__(self, src, src_type='discover'):   
        """Creates a object for analyzing text
    
        Keyword arguments:
        src (str) -- text, path to file, or url
        src_type (str) -- The type of input (text, path, url, discover)"""

       
        if isinstance(src, str) == False or len(src) <= 0:
            raise exception('Source must be a valid string, filepath or a valid URL')

        self._src = src
        self._src_type = src_type
        self._content = None
        self._orig_content = None


    def discover_url(self):
        self._src.startswith('http')
        self._src_type = 'url'
        url = 'https://www.webucator.com/how-to/address-by-bill-clinton-1997.cfm'
        r = requests.get(self._src)
        res = r.content
        self._orig_content = r.text
        self._content = res

    def discover_path(self):
        self._src.endswith('.txt')
        src_type = 'path'
        with open('pride-and-prejudice.txt') as f:
            self._content = self._orig_content
     

    def discover_text(self):
        src_type = 'text'
        text = ("The outlook wasn't brilliant for the Mudville Nine that day;the score stood four to two, with but one inning more to play. And then when Cooney died at first, and Barrows did the same, a sickly silence fell upon the patrons of the game.")
        self._orig_content = self._src
        self._content = self._src
Here is the test code for this part:

import unittest

url = 'https://www.webucator.com/how-to/address-by-bill-clinton-1997.cfm'
path = 'pride-and-prejudice.txt'
text = '''The outlook wasn't brilliant for the Mudville Nine that day;
the score stood four to two, with but one inning more to play.
And then when Cooney died at first, and Barrows did the same,
a sickly silence fell upon the patrons of the game.'''

class TestTextAnalyzer(unittest.TestCase):
    def test_discover_url(self):
        ta = TextAnalyzer(url)
        self.assertEqual(ta._src_type, 'url')
    def test_discover_path(self):
        ta = TextAnalyzer(path)
        self.assertEqual(ta._src_type, 'path')
    def test_discover_text(self):
        ta = TextAnalyzer(text)
        self.assertEqual(ta._src_type, 'text')
Reply


Messages In This Thread
Test Case Assertion Error - by moga2003 - Mar-07-2019, 03:39 AM
RE: Test Case Assertion Error - by ichabod801 - Mar-07-2019, 04:03 AM
RE: Test Case Assertion Error - by moga2003 - Mar-09-2019, 12:53 AM
RE: Test Case Assertion Error - by ichabod801 - Mar-09-2019, 02:56 AM
RE: Test Case Assertion Error - by moga2003 - Mar-09-2019, 06:00 PM
RE: Test Case Assertion Error - by ichabod801 - Mar-09-2019, 06:48 PM
RE: Test Case Assertion Error - by moga2003 - Mar-10-2019, 01:20 AM
RE: Test Case Assertion Error - by ichabod801 - Mar-10-2019, 01:46 AM
RE: Test Case Assertion Error - by moga2003 - Mar-11-2019, 03:04 AM
RE: Test Case Assertion Error - by ichabod801 - Mar-11-2019, 03:34 AM
RE: Test Case Assertion Error - by moga2003 - Mar-18-2019, 01:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 918 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Switch case or match case? Frankduc 9 4,387 Jan-20-2022, 01:56 PM
Last Post: Frankduc
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,068 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 3,062 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 2,511 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn
  opencv on mac: Assertion Failed RandomCoder 0 1,637 Feb-16-2020, 06:17 PM
Last Post: RandomCoder
  Assertion Error Mateoo 2 2,143 Jan-20-2019, 03:59 PM
Last Post: stullis
  error: (-215:Assertion failed) gkiller007 1 8,632 Jan-04-2019, 04:27 AM
Last Post: stullis
  pytest fixture in conftest.py thrown error while in the test file runs OzzieOzzum 1 3,933 Jul-31-2018, 12:12 PM
Last Post: OzzieOzzum
  Is this a normal/benign make test error when building python3.6 sofuego 2 3,476 Feb-12-2018, 12:32 AM
Last Post: sofuego

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020