is_relevant_table_row should raise a custom exception for unknown items, find_relevant_table_rows should handle the rest
This commit is contained in:
parent
3959aff10e
commit
d46148a510
10
src/mwfin/exceptions.py
Normal file
10
src/mwfin/exceptions.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class WrongAssumptions(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class UnexpectedMarkup(WrongAssumptions):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class UnknownFinancialStatementItem(WrongAssumptions):
|
||||||
|
pass
|
@ -7,6 +7,7 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
from mwfin import functions
|
from mwfin import functions
|
||||||
from mwfin.constants import HTML_PARSER, BASE_URL, FIN_STMT_URL_SUFFIX, IS, BS, CF, END_DATE
|
from mwfin.constants import HTML_PARSER, BASE_URL, FIN_STMT_URL_SUFFIX, IS, BS, CF, END_DATE
|
||||||
|
from mwfin.exceptions import UnknownFinancialStatementItem
|
||||||
|
|
||||||
|
|
||||||
THIS_DIR = Path(__file__).parent
|
THIS_DIR = Path(__file__).parent
|
||||||
@ -62,7 +63,8 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
test_soup = BeautifulSoup('<tr><td><div> Cash & Short Term Investments Growth </div></td></tr>', HTML_PARSER)
|
test_soup = BeautifulSoup('<tr><td><div> Cash & Short Term Investments Growth </div></td></tr>', HTML_PARSER)
|
||||||
self.assertFalse(functions.is_relevant_table_row(test_soup.tr))
|
self.assertFalse(functions.is_relevant_table_row(test_soup.tr))
|
||||||
test_soup = BeautifulSoup('<tr><td><div> baz </div></td></tr>', HTML_PARSER)
|
test_soup = BeautifulSoup('<tr><td><div> baz </div></td></tr>', HTML_PARSER)
|
||||||
self.assertFalse(functions.is_relevant_table_row(test_soup.tr))
|
with self.assertRaises(UnknownFinancialStatementItem):
|
||||||
|
functions.is_relevant_table_row(test_soup.tr)
|
||||||
|
|
||||||
@patch.object(functions, 'is_relevant_table_row')
|
@patch.object(functions, 'is_relevant_table_row')
|
||||||
def test_find_relevant_table_rows(self, mock_is_relevant_table_row):
|
def test_find_relevant_table_rows(self, mock_is_relevant_table_row):
|
||||||
@ -72,6 +74,11 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
self.assertListEqual(expected_output, output)
|
self.assertListEqual(expected_output, output)
|
||||||
mock_is_relevant_table_row.assert_has_calls([call(expected_output[0]), call(expected_output[1])])
|
mock_is_relevant_table_row.assert_has_calls([call(expected_output[0]), call(expected_output[1])])
|
||||||
|
|
||||||
|
mock_is_relevant_table_row.side_effect = UnknownFinancialStatementItem()
|
||||||
|
expected_output = self.test_soup.find_all('thistagdoesntexist')
|
||||||
|
output = functions.find_relevant_table_rows(self.test_soup)
|
||||||
|
self.assertListEqual(expected_output, output)
|
||||||
|
|
||||||
def test_extract_row_data(self):
|
def test_extract_row_data(self):
|
||||||
test_row = self.test_soup.find('div', attrs={'class': 'financials'}).tbody.tr
|
test_row = self.test_soup.find('div', attrs={'class': 'financials'}).tbody.tr
|
||||||
expected_output = ('Cash & Short Term Investments', (11000000, -22000000))
|
expected_output = ('Cash & Short Term Investments', (11000000, -22000000))
|
||||||
|
Loading…
Reference in New Issue
Block a user