-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#324 create table from state space results - with tests
* Trimmed SD not implemented
- Loading branch information
IanGrimstead
authored and
IanGrimstead
committed
Sep 19, 2019
1 parent
01d45a3
commit a2e0bc9
Showing
3 changed files
with
87 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,53 @@ | ||
import unittest | ||
|
||
from scripts.vandv.ssm_reporting import html_table | ||
from bs4 import BeautifulSoup | ||
|
||
from scripts.vandv.ssm_reporting import html_table, summary_html_table | ||
|
||
|
||
def extract_table_text_from_html(soup): | ||
for tag in soup.children: | ||
if tag.name == 'table': | ||
table_text = tag.text.replace('\n\n', '§').replace('\n', ' ').replace('§', '\n').strip() | ||
table_lines = [x.strip() for x in table_text.split('\n')] | ||
return '\n'.join(table_lines) | ||
return None | ||
|
||
|
||
class SSMReporting(unittest.TestCase): | ||
def test_html_table(self): | ||
results = { | ||
'sample term': {2: 78, 3: 60} | ||
'sample term': {2: 78, 3: 60}, | ||
'extra term': {2: 93, 3: 87} | ||
} | ||
expected_text = '''terms 2 3 | ||
sample term 78 60 | ||
extra term 93 87''' | ||
|
||
output_html = html_table(results, [2, 3]) | ||
|
||
self.assertEqual( | ||
''' | ||
''' | ||
, output_html | ||
) | ||
soup = BeautifulSoup(output_html, 'html.parser') | ||
|
||
actual_text = extract_table_text_from_html(soup) | ||
self.assertEqual(expected_text, actual_text) | ||
|
||
def test_summary_html_table(self): | ||
results = { | ||
'sample term': {2: 80, 3: 60}, | ||
'extra term': {2: 90, 3: 60}, | ||
'third term': {2: 100, 3: 60}, | ||
'fourth term': {2: 1000, 3: -200}, | ||
'fifth term': {2: -2000, 3: 600} | ||
} | ||
expected_text = '''terms 2 3 | ||
Mean -146 116 | ||
Trimmed (20% cut) mean 90 60 | ||
Standard deviation 1108.82 293.053''' | ||
# Trimmed (10% cut) standard deviation 455.073 0''' | ||
|
||
output_html = summary_html_table(results, [2, 3], trimmed_proportion_to_cut=0.2) | ||
|
||
soup = BeautifulSoup(output_html, 'html.parser') | ||
|
||
actual_text = extract_table_text_from_html(soup) | ||
self.assertEqual(expected_text, actual_text) |