Compare commits
2 Commits
29c82a4ff7
...
9a9ee461b1
Author | SHA1 | Date | |
---|---|---|---|
9a9ee461b1 | |||
e9b427ac4c |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
|
# Virtual environment
|
||||||
/.venv/
|
/.venv/
|
||||||
|
# PyCharm:
|
||||||
/.idea/
|
/.idea/
|
||||||
|
# Distribution / packaging:
|
||||||
|
*.egg-info/
|
@ -0,0 +1 @@
|
|||||||
|
from .scrape import *
|
@ -5,7 +5,7 @@ import csv
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .scrape import get_all_data, log
|
from . import get_all_data, log
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
32
tests/test_scrape.py
Normal file
32
tests/test_scrape.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from unittest import TestCase
|
||||||
|
from unittest.mock import patch, MagicMock, call
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from stocksymbolscraper import scrape
|
||||||
|
|
||||||
|
|
||||||
|
class ScrapeTestCase(TestCase):
|
||||||
|
|
||||||
|
@patch.object(scrape, 'get_single_tr_data')
|
||||||
|
def test_extract_row_data(self, mock_get_single_tr_data: MagicMock):
|
||||||
|
foo = 'foo'
|
||||||
|
mock_get_single_tr_data.return_value = foo
|
||||||
|
input1, input2, input3 = MagicMock(), MagicMock(), MagicMock()
|
||||||
|
# Although the function expects BS4 Tag objects as arguments, we substitute with Mocks here
|
||||||
|
# because those arguments are immediately passed into another function, which we mock out anyway.
|
||||||
|
output = scrape.extract_row_data(input1, input2, input3)
|
||||||
|
expected_output = [foo, foo, foo]
|
||||||
|
self.assertListEqual(expected_output, output)
|
||||||
|
mock_get_single_tr_data.assert_has_calls([call(input1), call(input2), call(input3)])
|
||||||
|
|
||||||
|
def test_get_str_from_td(self):
|
||||||
|
expected_output = 'foo bar'
|
||||||
|
test_td = BeautifulSoup(f'<td> {expected_output} </td>', 'html.parser').td
|
||||||
|
output = scrape.get_str_from_td(test_td)
|
||||||
|
self.assertEqual(expected_output, output)
|
||||||
|
|
||||||
|
expected_output = ''
|
||||||
|
test_td = BeautifulSoup('<td></td>', 'html.parser').td
|
||||||
|
output = scrape.get_str_from_td(test_td)
|
||||||
|
self.assertEqual(expected_output, output)
|
Loading…
Reference in New Issue
Block a user