-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added small testing harness / framework
- Loading branch information
Showing
9 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import * | ||
from types import TracebackType | ||
import traceback | ||
import sys | ||
import os | ||
from ..utils import * | ||
from .test import Test | ||
from .fail_test import FailTest | ||
from .throw_test import ThrowTest | ||
|
||
|
||
tests: List[Test] = [Test(), FailTest(), ThrowTest()] | ||
|
||
result_fmt = '{:18s}' | ||
name_fmt = '{:16s} ' | ||
print('{}{}'.format(name_fmt, result_fmt).format('Test Name', 'Test Result')) | ||
|
||
for test in tests: | ||
print(name_fmt.format(test.name()), end='') | ||
|
||
result: Union[bool, Tuple[type, Exception, TracebackType]] = test.run() | ||
if test.shouldFail(): | ||
if result == False: | ||
print('Ok!') | ||
elif t == True: | ||
print(result_fmt.format('Failed')) | ||
else: | ||
exc_type, exc_value, exc_traceback = result | ||
print(result_fmt.format('Failed with exception:')) | ||
print('\n'.join([''] + traceback.format_tb(exc_traceback)).replace('\n', '\n ')) | ||
elif test.shouldThrow(): | ||
if result == True: | ||
print(result_fmt.format('Failed (should throw)')) | ||
elif result == False: | ||
print(result_fmt.format('Failed (should throw)')) | ||
else: | ||
exc_type, exc_value, exc_traceback = result | ||
print(result_fmt.format('Ok, threw:')) | ||
print('\n'.join([''] + traceback.format_tb(exc_traceback)).replace('\n', '\n ')) | ||
else: | ||
if result == True: | ||
print('Ok!') | ||
elif result == False: | ||
print(result_fmt.format('Failed')) | ||
else: | ||
exc_type, exc_value, exc_traceback = result | ||
print(result_fmt.format('Failed with exception:')) | ||
print('\n'.join([''] + traceback.format_tb(exc_traceback)).replace('\n', '\n ')) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import * | ||
from .test import Test | ||
|
||
class FailTest(Test): | ||
def __init__(self): | ||
Test.__init__(self) | ||
|
||
def name(self) -> str: | ||
return 'fail test' | ||
|
||
def shouldThrow(self) -> bool: | ||
return False | ||
|
||
def shouldFail(self) -> bool: | ||
return True | ||
|
||
def test(self) -> bool: | ||
return False | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import * | ||
from types import TracebackType | ||
import traceback | ||
import sys | ||
|
||
class Test: | ||
def __init__(self): | ||
pass | ||
|
||
def name(self) -> str: | ||
return 'base test' | ||
|
||
def shouldThrow(self) -> bool: | ||
return False | ||
|
||
def shouldFail(self) -> bool: | ||
return False | ||
|
||
def test(self) -> bool: | ||
return True | ||
|
||
def run(self) -> Union[bool, Tuple[type, Exception, TracebackType]]: | ||
try: | ||
return self.test() | ||
except Exception as e: | ||
return sys.exc_info() |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import * | ||
from .test import Test | ||
|
||
class ThrowTest(Test): | ||
def __init__(self): | ||
Test.__init__(self) | ||
|
||
def name(self) -> str: | ||
return 'base test' | ||
|
||
def shouldThrow(self) -> bool: | ||
return True | ||
|
||
def shouldFail(self) -> bool: | ||
return False | ||
|
||
def test(self) -> bool: | ||
raise Exception('You should be seeing this.') |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from PyQt5 import QtWidgets, QtCore, uic, QtGui | ||
from PyQt5.QtGui import * | ||
from types import * | ||
|
||
class HapiSourceWidget(QtWidgets.QTextEdit): | ||
def __init__(self, title: str, authors: List[str], year: str, doi: Optional[str]): | ||
self.title = title | ||
self.authors = authors | ||
self.year = year | ||
if doi == None: | ||
self.doi = '' | ||
else: | ||
self.doi = doi | ||
|
||
QtWidgets.QTextEdit.__init__(self) | ||
self.setReadOnly(True) | ||
self.setAcceptRichText(True) | ||
self.setHtml(self.generate_html) | ||
self.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Maximum) | ||
|
||
def generate_latex(self) -> str: | ||
pass | ||
|
||
def generate_html(self) -> str: | ||
pass | ||
|
||
def generate_plain_text(self) -> str: | ||
authors_str = '' | ||
for author in self.authors: | ||
authors_str = '{}{}, '.format(authors_str, author) | ||
return '{}{} ({}) {}'.format(authors_str, self.title, self.year, self.doi).strip() |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
python3 -m src.test |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
python3 -m src.test |