Skip to content

Commit

Permalink
Added small testing harness / framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarns275 committed May 30, 2018
1 parent 58e6770 commit 6afede2
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
Empty file modified run
100644 → 100755
Empty file.
48 changes: 48 additions & 0 deletions src/test/__main__.py
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 '))
20 changes: 20 additions & 0 deletions src/test/fail_test.py
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


26 changes: 26 additions & 0 deletions src/test/test.py
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()
18 changes: 18 additions & 0 deletions src/test/throw_test.py
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.')
9 changes: 9 additions & 0 deletions src/widgets/graph_display_window_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
from PyQt5.QtChart import *
from utils.log import *
from widgets.gui import GUI
from random import randint

class GraphDisplayWindowGui(GUI, QtWidgets.QWidget):

@staticmethod
def generate_random_color(r, g, b):
"""
@returns a tuple, containing 3 integers between 0 and 255 which represent the r, g, and b values of a color.
"""
return ((randint(0, 255) + r) / 2, (randint(0, 255) + g) / 2, (randint(0, 255) + b) / 2)

def __init__(self):
QtWidgets.QWidget.__init__(self)
GUI.__init__(self)
Expand Down
31 changes: 31 additions & 0 deletions src/widgets/hapi_source_widget.py
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()
2 changes: 2 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
python3 -m src.test
1 change: 1 addition & 0 deletions test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 -m src.test

0 comments on commit 6afede2

Please sign in to comment.