Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Sep 20, 2023
1 parent 2a9001d commit 268c586
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
6 changes: 2 additions & 4 deletions finalcif/appwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self, file: Optional[Path] = None):
self.options = Options(self.ui, self.settings)
self.deposit = CODdeposit(self.ui, self.cif, self.options)
self.equipment = Equipment(app=self, settings=self.settings)
self.properties = Properties(app=self, settings=self.settings)
self.properties = Properties(parent=self, settings=self.settings)
self.status_bar = StatusBar(ui=self.ui)
self.status_bar.show_message('FinalCif version {}'.format(VERSION))
self.authors: Optional[AuthorLoops] = None
Expand All @@ -114,9 +114,7 @@ def __init__(self, file: Optional[Path] = None):
self.ui.TemplatesStackedWidget.setCurrentIndex(0)
self.ui.MainStackedWidget.got_to_main_page()
self.set_initial_button_states()
if len(sys.argv) > 1 and not file:
self.load_cif_file(Path(sys.argv[1]))
elif file:
if file:
self.load_cif_file(file)
self.load_recent_cifs_list()
self.set_checkcif_output_font(self.ui.CheckcifPlaintextEdit)
Expand Down
11 changes: 6 additions & 5 deletions finalcif/equip_property/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
from finalcif.appwindow import AppWindow


class Properties:
def __init__(self, app: 'AppWindow', settings: FinalCifSettings):
self.app = app
class Properties(QtCore.QObject):
def __init__(self, parent: 'AppWindow', settings: FinalCifSettings):
super().__init__(parent=parent)
self.app = parent
self.settings = settings
if app:
if parent:
self.signals_and_slots()
self.app.ui.PropertiesTemplatesStackedWidget.setCurrentIndex(0)
self.app.ui.PropertiesEditTableWidget.verticalHeader().hide()
Expand Down Expand Up @@ -181,7 +182,7 @@ def export_property_template(self, filename: str = '') -> None:
return
show_general_warning('No permission to write file to {}'.format(Path(filename).resolve()))

def selected_template_name(self) -> None:
def selected_template_name(self) -> str:
return self.app.ui.PropertiesTemplatesListWidget.currentIndex().data()

def import_property_from_file(self, filename: str = '') -> None:
Expand Down
5 changes: 4 additions & 1 deletion finalcif/finalcif_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def main():
sys.excepthook = my_exception_hook
# windows_style = QStyleFactory.create('Fusion')
# app.setStyle(windows_style)
w = AppWindow()
file = None
if len(sys.argv) > 1 and Path(sys.argv[1]).is_file():
file = Path(sys.argv[1])
w = AppWindow(file=file)
app.setWindowIcon(QIcon(os.path.join(application_path, r'icon/finalcif2.png')))
w.setWindowTitle('FinalCif v{}'.format(VERSION))
# w.showMaximized() # For full screen view
Expand Down
3 changes: 1 addition & 2 deletions finalcif/tools/platon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import subprocess
import sys
import threading
import time
from contextlib import suppress
from pathlib import Path
Expand Down Expand Up @@ -35,7 +34,7 @@ def run_process(self):
self.Z = ''
self.process = QtCore.QProcess()
self.output_widget.clear()
threading.Thread(target=self._monitor_output_log).start()
QtCore.QTimer(self).singleShot(100, self._monitor_output_log)
# self.process.readyReadStandardOutput.connect(self.on_ready_read)
self.process.finished.connect(self._onfinished)
self.process.setWorkingDirectory(str(self.cif_file.parent))
Expand Down
5 changes: 3 additions & 2 deletions tests/test_template_edit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from pathlib import Path

from PyQt5.QtCore import Qt
from PyQt5.QtTest import QTest
Expand All @@ -8,7 +9,7 @@

class EquipmentTestCase(unittest.TestCase):
def setUp(self) -> None:
self.app = AppWindow()
self.app = AppWindow(Path('test-data/1000006.cif'))
self.app.equipment.import_equipment_from_file('test-data/Crystallographer_Details.cif')
self.app.hide()

Expand Down Expand Up @@ -38,7 +39,7 @@ def test_template_edit_click(self):

class PropertiesTestCase(unittest.TestCase):
def setUp(self) -> None:
self.app = AppWindow()
self.app = AppWindow(Path('test-data/1000006.cif'))
self.app.hide()

def property_edit_click(self, field: str):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_templated_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
from docx.table import Table

from finalcif import VERSION
from finalcif.appwindow import AppWindow
from finalcif.appwindow import AppWindow, app
from finalcif.cif.cif_file_io import CifContainer
from finalcif.report.templated_report import TemplatedReport


class TemplateReportTestCase(unittest.TestCase):
def setUp(self) -> None:
self.myapp = AppWindow()
self.testcif = Path('tests/examples/1979688.cif').absolute()
self.myapp.load_cif_file(self.testcif.resolve())
self.myapp = AppWindow(file=self.testcif)
self.myapp.ui.HAtomsCheckBox.setChecked(False)
self.myapp.ui.ReportTextCheckBox.setChecked(False)
self.myapp.ui.PictureWidthDoubleSpinBox.setValue(7.43)
Expand All @@ -26,7 +25,6 @@ def setUp(self) -> None:
self.reportdoc = self.myapp.cif.finalcif_file_prefixed(prefix='report_', suffix='-finalcif.docx')
self.report_zip = self.myapp.cif.finalcif_file_prefixed(prefix='', suffix='-finalcif.zip')
self.myapp.select_report_picture(Path('finalcif/icon/finalcif.png'))
self.myapp.hide()

def tearDown(self) -> None:
self.myapp.cif.finalcif_file.unlink(missing_ok=True)
Expand All @@ -40,6 +38,8 @@ def tearDown(self) -> None:
self.myapp.ui.docxTemplatesListWidget.setCurrentRow(num)
self.myapp.templates.remove_current_template()
self.myapp.ui.docxTemplatesListWidget.blockSignals(False)
self.myapp.close()
app.quit()

def import_templates(self):
# blocking signals, because signal gets fired after delete and crashes:
Expand Down

0 comments on commit 268c586

Please sign in to comment.