Compare commits
No commits in common. "d504ddfc33f5c4bd9c726ac7d9052a0af51830b2" and "652ded4cd9bbcc93b2ad5c7aa0d9a16c82437760" have entirely different histories.
d504ddfc33
...
652ded4cd9
@ -11,8 +11,6 @@ from bs4.element import ResultSet, Tag
|
|||||||
# the end dates of the reporting periods as strings (either years or quarters).
|
# the end dates of the reporting periods as strings (either years or quarters).
|
||||||
ResultDict = dict[str, Union[tuple[int], tuple[str]]]
|
ResultDict = dict[str, Union[tuple[int], tuple[str]]]
|
||||||
|
|
||||||
HTML_PARSER = 'html.parser'
|
|
||||||
|
|
||||||
|
|
||||||
async def soup_from_url(url: str, session: ClientSession = None) -> BeautifulSoup:
|
async def soup_from_url(url: str, session: ClientSession = None) -> BeautifulSoup:
|
||||||
"""
|
"""
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from pathlib import Path
|
|
||||||
from unittest import IsolatedAsyncioTestCase
|
from unittest import IsolatedAsyncioTestCase
|
||||||
from unittest.mock import patch, MagicMock, AsyncMock, call
|
from unittest.mock import patch, MagicMock, AsyncMock, call
|
||||||
|
|
||||||
@ -6,21 +5,14 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
from mwfin import functions
|
from mwfin import functions
|
||||||
|
|
||||||
|
|
||||||
THIS_DIR = Path(__file__).parent
|
|
||||||
|
|
||||||
|
|
||||||
class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|
||||||
# boiled down & accurate structure of a relevant data table
|
# boiled down & accurate structure of a relevant data table
|
||||||
# https://www.marketwatch.com/investing/stock/aapl/financials/cash-flow
|
# https://www.marketwatch.com/investing/stock/aapl/financials/cash-flow
|
||||||
# view page source @ line 2055
|
# view page source @ line 2055
|
||||||
TEST_HTML_FILE_PATH = Path(THIS_DIR, 'test_structure.html')
|
TEST_HTML = ''
|
||||||
|
TEST_SOUP = BeautifulSoup(TEST_HTML, 'html.parser')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls) -> None:
|
class FunctionsTestCase(IsolatedAsyncioTestCase):
|
||||||
with open(cls.TEST_HTML_FILE_PATH, 'r') as f:
|
|
||||||
test_html = f.read()
|
|
||||||
cls.test_soup = BeautifulSoup(test_html, functions.HTML_PARSER)
|
|
||||||
|
|
||||||
@patch.object(functions, 'ClientSession')
|
@patch.object(functions, 'ClientSession')
|
||||||
async def test_soup_from_url(self, mock_session_cls):
|
async def test_soup_from_url(self, mock_session_cls):
|
||||||
@ -41,7 +33,7 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
|
|
||||||
def test_extract_end_dates(self):
|
def test_extract_end_dates(self):
|
||||||
expected_output = ('End_Date_1', 'End_Date_2')
|
expected_output = ('End_Date_1', 'End_Date_2')
|
||||||
output = functions.extract_end_dates(self.test_soup)
|
output = functions.extract_end_dates(TEST_SOUP)
|
||||||
self.assertTupleEqual(expected_output, output)
|
self.assertTupleEqual(expected_output, output)
|
||||||
|
|
||||||
def test_find_relevant_table_rows(self):
|
def test_find_relevant_table_rows(self):
|
||||||
|
@ -5,39 +5,28 @@
|
|||||||
<title>Title</title>
|
<title>Title</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="financials">
|
<div><table aria-label="(something something) data table">
|
||||||
<header>
|
|
||||||
<h2><span>Foo table</span></h2>
|
|
||||||
<small> All values USD.</small>
|
|
||||||
</header>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<table>
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><div> 'Item' </div><div> 'Item' </div></th>
|
<th><div> 'Item' </div><div> 'Item' </div></th>
|
||||||
<th><div> End_Date_1 </div></th>
|
<th><div> End_Date_1 </div></th>
|
||||||
<th><div> End_Date_2 </div></th>
|
<th><div> End_Date_2 </div></th>
|
||||||
<th></th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><div> Item_1 </div><div> Item_1 </div></td>
|
<td><div> Item_1 </div><div class="other"> Item_1 </div></td>
|
||||||
<td></td>
|
<td><div><span class=""> 11M </span></div></td>
|
||||||
<td></td>
|
<td><div><span class="negative"> (22M) </span></div></td>
|
||||||
<td><div> <div data-chart-data="11000000.0,-22000000.0"><div></div></td>
|
<td><div> <div data-chart-data="11000000.0,-22000000.0"><div></div></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><div> Item_2 </div><div> Item_2 </div></td>
|
<td><div> Item_2 </div><div class="other"> Item_2 </div></td>
|
||||||
<td></td>
|
<td><div><span class="positive"> 12% </span></div></td>
|
||||||
<td></td>
|
<td><div><span class="negative"> 13% </span></div></td>
|
||||||
<td></td>
|
<td><div> <div data-chart-data="0.12bazbazbaz,-0.13bazbazbaz"> <div></div></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table></div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user