-
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.
Now use the same package structure as the main program when running t…
…ests.
- Loading branch information
Showing
9 changed files
with
200 additions
and
10 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
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,50 @@ | ||
import sys | ||
import threading | ||
from time import sleep | ||
|
||
sources = { | ||
'hapi': { | ||
'authors': ['R.V. Kochanov', 'I.E. Gordon', 'L.S. Rothman', 'P. Wcislo', 'C. Hill','J.S. Wilzewski'], | ||
'title': 'HITRAN Application Programming Interface (HAPI): A comprehensive approach to working with spectroscopic data', | ||
'year': '2016', | ||
'doi': '10.1016/j.jqsrt.2016.03.005' | ||
}, | ||
'hapiest': { | ||
'authors': ['W. Matt', 'J. Karns', 'B. Cairo', 'M. Sova', 'E. Messer', 'D. Lohmann', 'R.V. Kochanov', | ||
'I.E. Gordon', 'B. Tenbergen', 'S. Kanbur'], | ||
'title': 'HAPIEST: A GUI for HAPI', | ||
'year': '2018', | ||
'doi': None | ||
} | ||
} | ||
|
||
from test.test import Test | ||
from PyQt5 import QtGui, QtWidgets, QtCore | ||
from widgets.molecule_info_widget import MoleculeInfoWidget | ||
|
||
class MoleculeInfoTest(Test): | ||
def __init__(self): | ||
Test.__init__(self) | ||
|
||
def name(self) -> str: | ||
return 'molecule view test' | ||
|
||
def test(self) -> bool: | ||
app = QtWidgets.QApplication(sys.argv) | ||
|
||
window = QtWidgets.QMainWindow() | ||
def close_window(): | ||
sleep(0.25) | ||
# window.deleteLater() | ||
|
||
t = threading.Thread(target=close_window) | ||
t.start() | ||
items = QtWidgets.QWidget(window) | ||
layout = QtWidgets.QVBoxLayout() | ||
for k, v in sources.items(): | ||
layout.addWidget(HapiSourceWidget(v['title'], v['authors'], v['year'], v['doi'])) | ||
items.setLayout(layout) | ||
window.setCentralWidget(items) | ||
window.show() | ||
qt_result = app.exec_() | ||
return qt_result == 0 |
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,51 @@ | ||
import sys | ||
import threading | ||
from time import sleep | ||
|
||
sources = { | ||
'hapi': { | ||
'authors': ['R.V. Kochanov', 'I.E. Gordon', 'L.S. Rothman', 'P. Wcislo', 'C. Hill','J.S. Wilzewski'], | ||
'title': 'HITRAN Application Programming Interface (HAPI): A comprehensive approach to working with spectroscopic data', | ||
'year': '2016', | ||
'doi': '10.1016/j.jqsrt.2016.03.005' | ||
}, | ||
'hapiest': { | ||
'authors': ['W. Matt', 'J. Karns', 'B. Cairo', 'M. Sova', 'E. Messer', 'D. Lohmann', 'R.V. Kochanov', | ||
'I.E. Gordon', 'B. Tenbergen', 'S. Kanbur'], | ||
'title': 'HAPIEST: A GUI for HAPI', | ||
'year': '2018', | ||
'doi': None | ||
} | ||
} | ||
|
||
from .test import Test | ||
from PyQt5 import QtGui, QtWidgets, QtCore | ||
from ..widgets.molecule_info_widget import MoleculeInfoWidget | ||
from ..widgets. | ||
|
||
class MoleculeInfoTest(Test): | ||
def __init__(self): | ||
Test.__init__(self) | ||
|
||
def name(self) -> str: | ||
return 'molecule view test' | ||
|
||
def test(self) -> bool: | ||
app = QtWidgets.QApplication(sys.argv) | ||
|
||
window = QtWidgets.QMainWindow() | ||
def close_window(): | ||
sleep(0.25) | ||
# window.deleteLater() | ||
|
||
t = threading.Thread(target=close_window) | ||
t.start() | ||
items = QtWidgets.QWidget(window) | ||
layout = QtWidgets.QVBoxLayout() | ||
for k, v in sources.items(): | ||
layout.addWidget(HapiSourceWidget(v['title'], v['authors'], v['year'], v['doi'])) | ||
items.setLayout(layout) | ||
window.setCentralWidget(items) | ||
window.show() | ||
qt_result = app.exec_() | ||
return qt_result == 0 |
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,85 @@ | ||
from PyQt5.QtCore.Qt import * | ||
from PyQt5.QtWidgets import * | ||
import json | ||
import utils.log | ||
|
||
class MoleculeInfoWidget(QScrollArea): | ||
|
||
FIELDS = ['Formula', 'InChi', 'InChiKey', 'HITRANonline_ID', 'Categories', 'Aliases'] | ||
|
||
def __init__(self, json_file_name = None, parent = None): | ||
QScrollArea.__init__(self, parent) | ||
|
||
def create_field(text): | ||
field_name = text.lower() | ||
label = QLabel('<b>{}:</b>'.format(text)) | ||
value = QLabel() | ||
|
||
label.setTextFormat(TextFormat.RichText) | ||
value.setTextFormat(TextFormat.RichText) | ||
|
||
self.__dict__[field_name + "_label"] = label | ||
self.__dict__[field_name] = value | ||
|
||
self.name = QLabel() | ||
self.img = QWidget() | ||
|
||
map(create_field, MoleculeInfoWidget.FIELDS) | ||
|
||
self.aliases.setWordWrap(True) | ||
self.categories.setWordWrap(True) | ||
|
||
self.form_layout = QtWidgets.QFormLayout() | ||
self.form_layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.FieldsStayAtSizeHint) | ||
|
||
map(lambda x: self.form_layout.addRow(self.__dict__[x.lower() + '_label'], self.__dict__[x.lower()]), MoleculeInfoWidget.FIELDS) | ||
|
||
self.hlayout = QtWidgets.QHBoxLayout() | ||
self.hlayout.addWidget(self.img) | ||
self.hlayout.addWidget(self.name) | ||
|
||
self.vlayout = QtWidgets.QVBoxLayout() | ||
self.vlayout.addWidget(self.hlayout) | ||
self.vlayout.addWidget(self.form_layout) | ||
self.setWidget(self.vlayout) | ||
|
||
if json_file_name == None: | ||
pass | ||
else: | ||
self.data = None | ||
try: | ||
with open('res/molecules/{}.json'.format(json_file_name), 'r') as file: | ||
text = file.read() | ||
self.data = json.loads(text) | ||
except Exception as e: | ||
log('No such molecule \'{}\''.format(json_file_name)) | ||
if self.data != None: | ||
self.restructure_aliases() | ||
try: | ||
self.name.setText(self.data['short_alias']) | ||
self.formula.setText(self.data['ordinary_formula_html']) | ||
if 'hitranonline_id' in self.data and self.data['hitranonline_id'] != None: | ||
self.hitranonline_id.setText(str(self.data['hitranonline_id'])) | ||
self.inchi.setText(self.data['inchi']) | ||
self.inchikey.setText(self.data['aliases']['inchikey']) | ||
|
||
alias_text = '' | ||
for ty, alias in self.data['aliases'].items(): | ||
alias_text = '{}<br>{}: {}'.format(alias_text, str(ty), str(alias)) | ||
self.aliases.setText(alias_text) | ||
|
||
categories_text = '' | ||
for categorie in self.data['categories']: | ||
categories_text = '{}<br>{}'.format(categories_text, str(categorie)) | ||
self.categories.setText(categories_text) | ||
|
||
except Exception as e: | ||
err_log('Encountered error \'{}\' - likely a malformed molecule json file'.format(str(e))) | ||
|
||
def restructure_aliases(self): | ||
if 'aliases' in self.data: | ||
reformatted = {} | ||
for item in self.data['aliases'].items(): | ||
reformatted[item['type']] = item['alias'] | ||
self.data['aliases'] = reformatted | ||
|
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 +1 @@ | ||
python3 -m src.test | ||
python3 src test |