Mar-09-2019, 06:00 PM
ok, I have re-written it. I am a little uncertain if it should be get_values or set_values. When I run the test code, it still returns the same errors.
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 = [] self._orig_content = [] def get_values(self): if self._src.endswith('.txt'): self._src_type = 'path' self._content = self.read_file(self._src) elif self._src.startswith('http'): self._src_type = 'url' r = requests.get(self._src) res = r.content self._orig_content = r.text self._content = res else: self._src_type = 'text' self._orig_content = self._src self._content = self._src
Error:FAIL: test_discover_path (__main__.TestTextAnalyzer)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-13-bce1ccf365eb>", line 16, in test_discover_path
self.assertEqual(ta._src_type, 'path')
AssertionError: 'discover' != 'path'
- discover
+ path
FAIL: test_discover_text (__main__.TestTextAnalyzer)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-13-bce1ccf365eb>", line 19, in test_discover_text
self.assertEqual(ta._src_type, 'text')
AssertionError: 'discover' != 'text'
- discover
+ text
FAIL: test_discover_url (__main__.TestTextAnalyzer)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-13-bce1ccf365eb>", line 13, in test_discover_url
self.assertEqual(ta._src_type, 'url')
AssertionError: 'discover' != 'url'
- discover
+ url