Exemplo n.º 1
0
class TablesTestMixin():
    def setUp(self) -> None:
        os.chdir(Path(__file__).absolute().parent.parent)
        self.testcif = Path('tests/examples/1979688.cif').absolute()
        self.myapp = AppWindow(self.testcif)
        self.myapp.ui.HAtomsCheckBox.setChecked(False)
        self.myapp.ui.ReportTextCheckBox.setChecked(False)
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(0.0)
        # make sure to use no template:
        self.myapp.ui.TemplatesListWidget.setCurrentRow(0)
        self.myapp.running_inside_unit_test = True
        self.myapp.hide()
        self.reportdoc = Path('report_' + self.testcif.stem + '-finalcif.docx')
        self.report_zip = Path(self.testcif.stem + '-finalcif.zip')
        self.myapp.hide()
        app.processEvents()

    def tearDown(self) -> None:
        self.myapp.final_cif_file_name.unlink(missing_ok=True)
        self.reportdoc.unlink(missing_ok=True)
        self.report_zip.unlink(missing_ok=True)
        self.myapp.ui.ReportTextCheckBox.setChecked(False)
        self.myapp.ui.HAtomsCheckBox.setChecked(False)
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(7.5)
        self.myapp.close()
Exemplo n.º 2
0
class TestFileIsOpened(unittest.TestCase):
    """A CIF fle in a complete work folder"""
    def setUp(self) -> None:
        os.chdir(Path(__file__).absolute().parent.parent)
        self.testcif = Path(
            'tests/examples/work/cu_BruecknerJK_153F40_0m.cif').absolute()
        self.myapp = AppWindow(self.testcif)
        self.myapp.hide()
        self.myapp.setWindowIcon(QIcon('./icon/multitable.png'))
        self.myapp.setWindowTitle('FinalCif v{}'.format(VERSION))
        Path('foo.cif').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.cif').unlink(missing_ok=True)

    def tearDown(self) -> None:
        Path('foo.cif').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.cif').unlink(missing_ok=True)
        self.myapp.close()

    def test_save_action(self):
        self.myapp.save_current_cif_file()
        self.assertEqual(
            True,
            Path('cu_BruecknerJK_153F40_0m-finalcif.cif').exists())

    def test_save_file(self):
        self.myapp.save_current_cif_file('foo.cif')
        self.assertEqual(True, Path('foo.cif').exists())
Exemplo n.º 3
0
class TestOptions(unittest.TestCase):
    def setUp(self) -> None:
        self.myapp = AppWindow()
        self.myapp.running_inside_unit_test = True
        self.myapp.ui.HAtomsCheckBox.setChecked(False)
        self.myapp.ui.ReportTextCheckBox.setChecked(False)
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(0.0)
        self.myapp.hide()

    def tearDown(self) -> None:
        self.myapp.ui.HAtomsCheckBox.setChecked(False)
        self.myapp.ui.ReportTextCheckBox.setChecked(False)
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(0.0)
        self.myapp.close()

    def test_save_picture_with(self):
        self.assertEqual(self.myapp.ui.PictureWidthDoubleSpinBox.value(), 0.0)
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(7.6)
        self.assertEqual(self.myapp.options.picture_width, 7.6)
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(12.5)
        self.assertEqual(self.myapp.options.picture_width, 12.5)

    def test_without_h(self):
        self.assertEqual(self.myapp.ui.HAtomsCheckBox.isChecked(), False)
        self.myapp.ui.HAtomsCheckBox.setChecked(True)
        self.assertEqual(self.myapp.options.without_h, True)
        self.myapp.ui.HAtomsCheckBox.setChecked(False)
        self.assertEqual(self.myapp.options.without_h, False)

    def test_report_text(self):
        self.assertEqual(self.myapp.ui.ReportTextCheckBox.isChecked(), False)
        self.myapp.ui.ReportTextCheckBox.setChecked(True)
        self.assertEqual(self.myapp.options.report_text, False)
        self.myapp.ui.ReportTextCheckBox.setChecked(False)
        self.assertEqual(self.myapp.options.report_text, True)

    def test_checkcif_url(self):
        self.assertEqual(
            self.myapp.ui.CheckCIFServerURLTextedit.text(),
            'https://checkcif.iucr.org/cgi-bin/checkcif_with_hkl')
        self.myapp.ui.CheckCIFServerURLTextedit.setText('foobar')
        self.assertEqual(self.myapp.options.checkcif_url, 'foobar')

    def test_option_picture_width(self):
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(0.0)
        # a width od < 0.001 defaults to 7.5 cm
        self.assertEqual(self.myapp.options.picture_width, 7.5)
        #
        self.myapp.ui.PictureWidthDoubleSpinBox.setValue(7.6)
        self.assertEqual(self.myapp.options.picture_width, 7.6)

    def test_without_H_option(self):
        self.myapp.ui.HAtomsCheckBox.setChecked(False)
        self.assertEqual(self.myapp.options.without_h, False)
Exemplo n.º 4
0
class TestCheckCifHTML(unittest.TestCase):

    def setUp(self) -> None:
        os.chdir(Path(__file__).absolute().parent.parent)
        self.myapp = AppWindow(Path('tests/examples/work/cu_BruecknerJK_153F40_0m.cif').absolute())
        self.myapp.hide()  # For full screen view
        self.resobj = Path('checkcif-' + strip_finalcif_of_name(self.myapp.cif.fileobj.stem) + '-finalcif.html')

    def tearDown(self) -> None:
        self.resobj.unlink(missing_ok=True)
        self.myapp.final_cif_file_name.unlink(missing_ok=True)
        Path('platon.out').unlink(missing_ok=True)
        Path('check.def').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.chk').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.gif').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.ins').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.lst').unlink(missing_ok=True)
        Path('checkcif-cu_BruecknerJK_153F40_0m-finalcif.html').unlink(missing_ok=True)
        Path('checkcif-cu_BruecknerJK_153F40_0m-finalcif.pdf').unlink(missing_ok=True)
        Path('checkpdf-cu_BruecknerJK_153F40_0m-finalcif.html').unlink(missing_ok=True)
        self.myapp.close()

    def equipment_click(self, field: str):
        self.myapp.ui.EquipmentTemplatesStackedWidget.setCurrentIndex(0)
        item = self.myapp.ui.EquipmentTemplatesListWidget.findItems(field, Qt.MatchStartsWith)[0]
        self.myapp.ui.EquipmentTemplatesListWidget.setCurrentItem(item)
        self.myapp.equipment.load_selected_equipment()

    @unittest.skip('temporary skip')
    def test_checkcif_html(self):
        """Runs a html checkcif without hkl and compares the result with the html file."""
        self.maxDiff = None
        self.equipment_click('D8 VENTURE')
        self.equipment_click('Crystallographer Details')
        self.myapp.ui.cif_main_table.setText(key='_chemical_absolute_configuration', txt='ad', column=COL_EDIT)
        # Remember: This test is without structure factors!
        self.myapp.ui.structfactCheckBox.setChecked(True)
        QTest.mouseClick(self.myapp.ui.CheckcifHTMLOnlineButton, Qt.LeftButton, Qt.NoModifier)
        time.sleep(5)
        # this is the file on github:
        html_as_it_is_expected = Path('checkcif-' + strip_finalcif_of_name(self.myapp.cif.fileobj.stem) + '-test.html')
        htmlfile = html_as_it_is_expected.read_text().splitlines()[28:-13]
        # this is the new downloadad file
        result = self.resobj.read_text().splitlines()[28:-13]
        self.assertEqual(htmlfile, result)
Exemplo n.º 5
0
class TestStausBarWithGraphics(unittest.TestCase):
    def setUp(self) -> None:
        self.myapp = AppWindow()
        self.myapp.running_inside_unit_test = True
        self.myapp.setWindowIcon(QIcon('./icon/multitable.png'))
        self.myapp.setWindowTitle('FinalCif v{}'.format(VERSION))
        self.status = StatusBar(self.myapp.ui)
        self.myapp.hide()

    def tearDown(self) -> None:
        self.myapp.close()

    def test_show_hello(self):
        self.status.show_message('Hello!')
        self.assertEqual('Hello!', self.status.current_message)

    def test_show_list(self):
        self.status.show_message(['Hello', 'world!'])
        self.assertEqual('Hello world!', self.status.current_message)

    def test_show_2s(self):
        self.status.show_message('foobar', timeout=1)
        self.assertEqual('foobar', self.status.current_message)
Exemplo n.º 6
0
class TestNothingOpened(unittest.TestCase):
    """A CIF fle in a complete work folder"""
    def setUp(self) -> None:
        os.chdir(Path(__file__).absolute().parent.parent)
        self.myapp = AppWindow()
        self.myapp.running_inside_unit_test = True
        self.myapp.hide()
        self.myapp.setWindowIcon(QIcon('./icon/multitable.png'))
        self.myapp.setWindowTitle('FinalCif v{}'.format(VERSION))
        Path('foo.cif').unlink(missing_ok=True)
        Path('cu_BruecknerJK_153F40_0m-finalcif.cif').unlink(missing_ok=True)

    def tearDown(self) -> None:
        self.myapp.close()

    def test_save_noting(self):
        self.myapp.save_current_cif_file()
        self.assertEqual(
            False,
            Path('cu_BruecknerJK_153F40_0m-finalcif.cif').exists())

    def test_save_file(self):
        self.myapp.save_current_cif_file('foo.cif')
        self.assertEqual(False, Path('foo.cif').exists())
Exemplo n.º 7
0
class TestLoops(unittest.TestCase):

    def setUp(self) -> None:
        os.chdir(Path(__file__).resolve().parent.parent)
        self.testcif = Path('tests/examples/1979688.cif').resolve()
        self.myapp = AppWindow(self.testcif)
        self.myapp.running_inside_unit_test = True
        self.myapp.hide()  # For full screen view
        self.myapp.ui.LoopsPushButton.click()

    def tearDown(self) -> None:
        self.myapp.final_cif_file_name.unlink(missing_ok=True)
        self.myapp.close()

    def get_index_of(self, loopkey: str = ''):
        tabw: QTabWidget = self.myapp.ui.LoopsTabWidget
        tab = -1
        for tab in range(tabw.count()):
            if tabw.tabText(tab).startswith(loopkey):
                break
            else:
                tab = -1
        return tab

    def test_get_index_of_tab(self):
        self.assertEqual(2, self.get_index_of('CIF Author'))

    def test_loop_data(self):
        index = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('Citations')).model().index(0, 1)
        self.assertEqual('10.1021/acs.orglett.0c01078', index.data())

    def test_loop_data_atoms_aniso(self):
        index = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('Displacement Para')).model().index(0, 1)
        self.assertEqual('0.0161(10)', index.data())

    def test_loop_audit_author_name(self):
        index = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('CIF Author')).model().index(0, 0)
        self.assertEqual('Daniel Kratzert', index.data())

    def test_loop_audit_author_address(self):
        index = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('CIF Author')).model().index(0, 1)
        self.assertEqual(unify_line_endings('University of Freiburg\nGermany'), unify_line_endings(index.data()))

    def test_loop_dots(self):
        index = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('Bonds')).model().index(1, 3)
        self.assertEqual('.', index.data())

    def test_loop_question_marks(self):
        index = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('Bonds')).model().index(1, 4)
        self.assertEqual('?', index.data())

    def test_loop_no_edit(self):
        self.myapp.ui.SaveCifButton.click()
        c = CifContainer(self.myapp.final_cif_file_name)
        self.assertEqual('0.0181', c.loops[3].val(0, 2))

    def test_loop_edit_one_single_field(self):
        model = self.myapp.ui.LoopsTabWidget.widget(self.get_index_of('Scattering')).model()
        print(self.myapp.ui.LoopsTabWidget.tabText(4))
        model.setData(model.index(0, 2), 'foo bar', role=Qt.EditRole)
        self.myapp.ui.SaveCifButton.click()
        c = CifContainer(self.myapp.final_cif_file_name)
        self.assertEqual('foo bar', as_string(c.loops[3].val(0, 2)))
Exemplo n.º 8
0
class TestMainTableFieldBehavior(unittest.TestCase):
    def setUp(self) -> None:
        os.chdir(Path(__file__).absolute().parent.parent)
        self.testcif = Path('tests/examples/1979688.cif').absolute()
        self.myapp = AppWindow(self.testcif)
        self.myapp.running_inside_unit_test = True
        self.myapp.hide()  # For full screen view

    def tearDown(self) -> None:
        self.myapp.final_cif_file_name.unlink(missing_ok=True)
        self.myapp.close()

    def key_row(self, key: str) -> int:
        return self.myapp.ui.cif_main_table.row_from_key(key)

    def cell_widget(self, row: int, col: int) -> str:
        return str(self.myapp.ui.cif_main_table.cellWidget(row, col).__class__)

    def cell_text(self, key: str, col: int) -> str:
        return unify_line_endings(
            self.myapp.ui.cif_main_table.getTextFromKey(key, col))

    def equipment_click(self, field: str):
        self.myapp.ui.EquipmentTemplatesStackedWidget.setCurrentIndex(0)
        item = self.myapp.ui.EquipmentTemplatesListWidget.findItems(
            field, Qt.MatchStartsWith)[0]
        self.myapp.ui.EquipmentTemplatesListWidget.setCurrentItem(item)
        self.myapp.equipment.load_selected_equipment()

    def get_background_color(self, key: str, col: int) -> QColor:
        return self.myapp.ui.cif_main_table.itemFromKey(
            key, col).background().color()

    ######

    def test_rowcounts(self):
        self.assertEqual(130, self.myapp.ui.cif_main_table.rowCount())

    def test_delete_row(self):
        self.myapp.ui.cif_main_table.delete_row(
            self.key_row('_audit_update_record'))
        self.assertEqual(129, self.myapp.ui.cif_main_table.rowCount())

    def test_delete_and_reappear(self):
        self.myapp.ui.cif_main_table.delete_row(16)
        # cline count stays the same:
        self.assertEqual(130, self.myapp.ui.cif_main_table.rowCount())
        self.assertEqual(
            '?', self.cell_text('_atom_sites_solution_primary', COL_CIF))
        # method comes from solution program now:
        self.assertEqual(
            'direct', self.cell_text('_atom_sites_solution_primary', COL_DATA))
        # This is an essential key, it reappears after reload:
        self.assertEqual(0, self.key_row('_atom_sites_solution_primary'))

    def test_get_text_from_item(self):
        self.assertEqual('geom',
                         self.myapp.ui.cif_main_table.item(15, COL_CIF).text())
        self.assertEqual(
            '',
            self.myapp.ui.cif_main_table.item(15, COL_DATA).text())
        self.assertEqual(
            '',
            self.myapp.ui.cif_main_table.item(15, COL_EDIT).text())

    def test_get_text_by_key(self):
        self.assertEqual(
            'geom', self.cell_text('_atom_sites_solution_hydrogens', COL_CIF))
        self.assertEqual(
            '', self.cell_text('_atom_sites_solution_hydrogens', COL_DATA))
        self.assertEqual(
            '', self.cell_text('_atom_sites_solution_hydrogens', COL_EDIT))

    def test_CCDC_in_equipment_list(self):
        self.assertEqual(
            'CCDC number',
            self.myapp.ui.EquipmentTemplatesListWidget.item(1).text())

    def test_load_equipment(self):
        # make sure contact author is selected
        self.equipment_click('Crystallographer Details')
        # It is important here, that the first column has '*****@*****.**' in it:
        self.assertEqual(
            '?',
            self.myapp.ui.cif_main_table.getTextFromKey(
                '_audit_contact_author_email', COL_CIF))
        self.assertEqual(
            '*****@*****.**',
            self.myapp.ui.cif_main_table.getTextFromKey(
                '_audit_contact_author_email', COL_DATA))
        self.assertEqual(
            '*****@*****.**',
            self.myapp.ui.cif_main_table.getTextFromKey(
                '_audit_contact_author_email', COL_EDIT))

    def test_field_types(self):
        self.assertEqual(
            "<class 'gui.custom_classes.MyTableWidgetItem'>",
            str(
                self.myapp.ui.cif_main_table.itemFromKey(
                    '_atom_sites_solution_hydrogens', COL_CIF).__class__))
        self.assertEqual(
            "<class 'NoneType'>",
            str(
                self.myapp.ui.cif_main_table.widget_from_key(
                    '_atom_sites_solution_hydrogens', COL_CIF).__class__))

    def test_combobox_field(self):
        self.assertEqual(
            "<class 'gui.custom_classes.MyComboBox'>",
            str(
                self.myapp.ui.cif_main_table.widget_from_key(
                    '_atom_sites_solution_hydrogens', COL_EDIT).__class__))

    def test_plaintextedit_field(self):
        self.assertEqual(
            "<class 'gui.custom_classes.MyQPlainTextEdit'>",
            str(
                self.myapp.ui.cif_main_table.widget_from_key(
                    '_audit_contact_author_address', COL_CIF).__class__))
        self.assertEqual(
            "<class 'gui.custom_classes.MyQPlainTextEdit'>",
            str(
                self.myapp.ui.cif_main_table.widget_from_key(
                    '_audit_contact_author_address', COL_DATA).__class__))
        self.assertEqual(
            "<class 'gui.custom_classes.MyQPlainTextEdit'>",
            str(
                self.myapp.ui.cif_main_table.widget_from_key(
                    '_audit_contact_author_address', COL_EDIT).__class__))
Exemplo n.º 9
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        current_file_path()
        self.testcif = Path('tests/examples/1979688.cif').resolve()
        self.app = AppWindow(self.testcif)
        self.app.running_inside_unit_test = True
        self.app.hide()
        self.author = {
            'address': 'address',
            'footnote': 'footnote',
            'email': 'email',
            'name': 'name',
            'orcid': 'orcid',
            'phone': 'phone',
            'contact': True
        }

    def tearDown(self) -> None:
        current_file_path()
        Path('tests/other_templates/testexport_author.cif').unlink(
            missing_ok=True)
        self.app.close()

    def _import_testauthor(self):
        # To be used in other tests
        self.app.authors.import_author('../other_templates/AATest_Author.cif')
        self.app.ui.LoopTemplatesListWidget.setCurrentRow(0)

    def test_selected_loop_without_selection(self):
        self.assertEqual(self.app.authors.get_selected_loop_name(), '')

    def test_selected_loop_with_selection(self):
        self._delete_test_author()
        self._import_testauthor()
        self.assertEqual('AATest Author',
                         self.app.authors.get_selected_loop_name())

    def _delete_test_author(self, name='AATest Author'):
        self._select_row_of_author(name)
        self.app.ui.DeleteLoopAuthorTemplateButton.click()
        self.assertNotEqual('AATest Author',
                            self.app.authors.get_selected_loop_name())

    def _select_row_of_author(self, name):
        listw = self.app.ui.LoopTemplatesListWidget
        for row in range(listw.count()):
            listw.setCurrentRow(row)
            if listw.currentItem().text().startswith(name):
                break

    def test_export_selected_author(self):
        self._delete_test_author()
        self._import_testauthor()
        self.app.authors.export_author_template(
            '../other_templates/testexport_author.cif')
        self.assertEqual(
            True,
            Path('../other_templates/testexport_author.cif').exists())
        self.assertEqual(
            Path('../other_templates/testexport_author.cif').read_text(),
            Path('../other_templates/testexport_author.cif').read_text())

    def test_set_name(self):
        self.app.ui.FullNameLineEdit.setText('test')
        self.assertEqual('test',
                         self.app.authors.get_author_info().get('name'))

    def test_set_contact_author(self):
        self.assertEqual(False, self.app.ui.ContactAuthorCheckBox.isChecked())
        self.app.ui.ContactAuthorCheckBox.setChecked(True)
        self.assertEqual(True,
                         self.app.authors.get_author_info().get('contact'))

    def test_set_address(self):
        self.app.ui.AddressTextedit.setText('Eine Adresse 1')
        self.assertEqual("'Eine Adresse 1'",
                         self.app.authors.get_author_info().get('address'))

    def test_set_footnote(self):
        self.app.ui.FootNoteLineEdit.setText('notex')
        self.assertEqual('notex',
                         self.app.authors.get_author_info().get('footnote'))

    def test_set_email(self):
        self.app.ui.EMailLineEdit.setText('*****@*****.**')
        self.assertEqual('*****@*****.**',
                         self.app.authors.get_author_info().get('email'))

    def test_set_orcid(self):
        self.app.ui.ORCIDLineEdit.setText('12345a')
        self.assertEqual('12345a',
                         self.app.authors.get_author_info().get('orcid'))

    def test_set_phone(self):
        self.app.ui.PhoneLineEdit.setText('12345a')
        self.assertEqual('12345a',
                         self.app.authors.get_author_info().get('phone'))

    def test_set_foo(self):
        self.assertEqual(None, self.app.authors.get_author_info().get('foo'))

    def test_set_author_info(self):
        self.app.authors.set_author_info(self.author)
        self.assertEqual('name', self.app.ui.FullNameLineEdit.text())
        self.assertEqual('address', self.app.ui.AddressTextedit.toPlainText())
        self.assertEqual('email', self.app.ui.EMailLineEdit.text())
        self.assertEqual('orcid', self.app.ui.ORCIDLineEdit.text())
        self.assertEqual('footnote', self.app.ui.FootNoteLineEdit.text())
        self.assertEqual('phone', self.app.ui.PhoneLineEdit.text())
        self.assertEqual(True, self.app.ui.ContactAuthorCheckBox.isChecked())

    def test_set_author_info_and_clear(self):
        self.app.authors.set_author_info(self.author)
        self.app.authors.clear_fields()
        self.assertEqual('', self.app.ui.FullNameLineEdit.text())
        self.assertEqual('', self.app.ui.AddressTextedit.toPlainText())
        self.assertEqual('', self.app.ui.EMailLineEdit.text())
        self.assertEqual('', self.app.ui.ORCIDLineEdit.text())
        self.assertEqual('', self.app.ui.FootNoteLineEdit.text())
        self.assertEqual('', self.app.ui.PhoneLineEdit.text())
        self.assertEqual(False, self.app.ui.ContactAuthorCheckBox.isChecked())

    def test_save_author(self):
        pass
Exemplo n.º 10
0
class TestWorkfolder(unittest.TestCase):
    """A CIF fle in a complete work folder"""
    def setUp(self) -> None:
        os.chdir(Path(__file__).absolute().parent.parent)
        self.testcif = Path(
            'tests/examples/work/cu_BruecknerJK_153F40_0m.cif').absolute()
        self.myapp = AppWindow(self.testcif)
        self.myapp.hide()
        self.myapp.setWindowIcon(QIcon('./icon/multitable.png'))
        self.myapp.setWindowTitle('FinalCif v{}'.format(VERSION))

    def tearDown(self) -> None:
        Path(self.testcif.stem + '.ins').unlink(missing_ok=True)
        Path(self.testcif.stem + '.lst').unlink(missing_ok=True)
        Path(self.testcif.stem + '.2fcf').unlink(missing_ok=True)
        Path('testcif_file.cif').unlink(missing_ok=True)
        self.myapp.close()

    def key_row(self, key: str) -> int:
        return self.myapp.ui.cif_main_table.row_from_key(key)

    def cell_widget(self, row: int, col: int) -> QWidget:
        return self.myapp.ui.cif_main_table.cellWidget(row, col)

    def cell_widget_class(self, row: int, col: int) -> str:
        return str(self.myapp.ui.cif_main_table.cellWidget(row, col).__class__)

    def get_combobox_items(self, row: int, col: int):
        widget = self.cell_widget(row, col)
        return [widget.itemText(i) for i in range(widget.count())]

    def cell_text(self, key: str, col: int) -> str:
        return unify_line_endings(
            self.myapp.ui.cif_main_table.getTextFromKey(key, col))

    def equipment_click(self, field: str):
        listw = self.myapp.ui.EquipmentTemplatesListWidget
        self.myapp.ui.EquipmentTemplatesStackedWidget.setCurrentIndex(0)
        item = listw.findItems(field, Qt.MatchStartsWith)[0]
        listw.setCurrentItem(item)
        self.assertEqual(field, item.text())
        rect = listw.visualItemRect(item)
        QTest.mouseDClick(listw.viewport(), Qt.LeftButton, Qt.NoModifier,
                          rect.center())
        app.processEvents()
        # This is necessary:
        self.myapp.equipment.load_selected_equipment()

    def get_background_color(self, key: str, col: int) -> QColor:
        return self.myapp.ui.cif_main_table.itemFromKey(
            key, col).background().color()

    def testDataColumn(self):
        self.myapp.hide()
        # test of ccdc number added from email during load:
        self.assertEqual(
            '1979688',
            self.cell_text('_database_code_depnum_ccdc_archive', COL_DATA))
        # '_computing_structure_solution:'
        self.assertEqual(
            'SHELXT (G. Sheldrick)',
            self.cell_text('_computing_structure_solution', COL_DATA))
        self.assertEqual(
            'direct', self.cell_text('_atom_sites_solution_primary', COL_DATA))
        self.assertEqual(
            '9624', self.cell_text('_cell_measurement_reflns_used', COL_DATA))
        self.assertEqual(
            '78.8605', self.cell_text('_cell_measurement_theta_max', COL_DATA))
        self.assertEqual(
            '2.547', self.cell_text('_cell_measurement_theta_min', COL_DATA))
        # Test for auto-fill data:
        self.assertEqual(
            'SAINT V8.40A',
            self.cell_text('_computing_cell_refinement', COL_DATA))
        self.assertEqual('?',
                         self.cell_text('_computing_cell_refinement', COL_CIF))
        self.assertEqual(
            'Bruker BIS V6.2.12/2019-08-12',
            self.cell_text('_computing_data_collection', COL_DATA))
        self.assertEqual(
            'SHELXT (G. Sheldrick)',
            self.cell_text('_computing_structure_solution', COL_DATA))
        self.assertEqual('1.1',
                         self.cell_text('_diffrn_source_current', COL_DATA))
        self.assertEqual('50.0',
                         self.cell_text('_diffrn_source_voltage', COL_DATA))
        self.assertEqual('colourless',
                         self.cell_text('_exptl_crystal_colour', COL_DATA))
        self.assertEqual(
            'plate', self.cell_text('_exptl_crystal_description', COL_DATA))
        # _exptl_crystal_recrystallization_method Yellow:
        self.assertEqual(
            '',
            self.cell_text('_exptl_crystal_recrystallization_method',
                           COL_DATA))
        # self.assertEqual('QPlainTextEdit {background-color: #faf796;}',
        #                 self.myapp.ui.cif_main_table.cellWidget(41, 1).styleSheet())
        self.assertEqual(
            """Sheldrick, G.M. (2015). Acta Cryst. A71, 3-8.\nSheldrick, G.M. (2015). Acta Cryst. C71, 3-8.""",
            self.cell_text('_publ_section_references', COL_DATA))
        self.assertEqual('geom',
                         self.cell_text('_atom_sites_solution_hydrogens', 0))
        self.assertEqual(
            '', self.cell_text('_atom_sites_solution_hydrogens', COL_DATA))
        self.assertEqual(
            """FinalCif V{} by Daniel Kratzert, Freiburg {}, https://github.com/dkratzert/FinalCif"""
            .format(VERSION,
                    datetime.now().year),
            self.cell_text('_audit_creation_method', COL_DATA))

    def test_abs_configuration_combo(self):
        self.assertEqual(10, self.key_row('_chemical_absolute_configuration'))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(10, COL_CIF))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(10, COL_DATA))
        self.assertEqual("<class 'gui.custom_classes.MyComboBox'>",
                         self.cell_widget_class(10, COL_EDIT))

    def test_diffrn_radiation_type_combo(self):
        row = self.key_row('_diffrn_radiation_type')
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(row, COL_CIF))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(row, COL_DATA))
        self.assertEqual("<class 'gui.custom_classes.MyComboBox'>",
                         self.cell_widget_class(row, COL_EDIT))

    def test_diffrn_ambient_temperature_combo(self):
        row = self.key_row('_diffrn_ambient_temperature')
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(row, COL_CIF))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(row, COL_DATA))
        self.assertEqual("<class 'gui.custom_classes.MyComboBox'>",
                         self.cell_widget_class(row, COL_EDIT))

    def test_combo_items_ambient_temp(self):
        row = self.key_row('_diffrn_ambient_temperature')
        self.assertEqual([
            '', '15(1)', '80(2)', '100(2)', '110(2)', '120(2)', '130(2)',
            '150(2)', '200(2)', '293.15(2)', '298(2)'
        ], self.get_combobox_items(row, COL_EDIT))

    def test_combo_items_radiation(self):
        row = self.key_row('_diffrn_radiation_type')
        self.assertEqual(['', 'Mo K\\a', 'Cu K\\a', 'Ag K\\a'],
                         self.get_combobox_items(row, COL_EDIT))

    def test_combo_items_exptl_crystal_description(self):
        row = self.key_row('_exptl_crystal_description')
        self.assertEqual(['', 'block', 'needle', 'plate', 'prism', 'sphere'],
                         self.get_combobox_items(row, COL_EDIT))

    def test_combo_items_atom_sites_solution_primary(self):
        row = self.key_row('_atom_sites_solution_primary')
        self.assertEqual([
            '', 'direct', 'vecmap', 'heavy', 'difmap', 'geom', 'disper',
            'isomor', 'notdet', 'dual', 'iterative', 'other'
        ], self.get_combobox_items(row, COL_EDIT))

    def test_combo_items_exptl_crystal_colour(self):
        row = self.key_row('_exptl_crystal_colour')
        self.assertEqual([
            '', 'colourless', 'white', 'black', 'yellow', 'red', 'blue',
            'green', 'gray', 'pink', 'orange', 'violet', 'brown'
        ], self.get_combobox_items(row, COL_EDIT))

    def test_background_color_data(self):
        self.assertEqual(
            light_green,
            self.get_background_color('_computing_cell_refinement', COL_DATA))
        self.assertEqual(
            light_green,
            self.get_background_color('_computing_data_collection', COL_DATA))
        self.assertEqual(
            light_green,
            self.get_background_color('_computing_data_reduction', COL_DATA))
        self.assertEqual(
            QColor(0, 0, 0, 255),
            self.get_background_color('_computing_molecular_graphics',
                                      COL_DATA))

    def test_chemical_formula_moiety(self):
        self.assertEqual('?',
                         self.cell_text('_chemical_formula_moiety', COL_CIF))
        self.assertEqual('',
                         self.cell_text('_chemical_formula_moiety', COL_DATA))
        self.assertEqual('',
                         self.cell_text('_chemical_formula_moiety', COL_EDIT))

    def test_background_color_theta_max(self):
        self.assertEqual(
            (0, 0, 0, 255),
            self.get_background_color('_cell_measurement_theta_max',
                                      COL_CIF).getRgb())
        self.assertEqual(
            light_green,
            self.get_background_color('_cell_measurement_theta_max', COL_DATA))
        self.assertEqual(
            (0, 0, 0, 255),
            self.get_background_color('_cell_measurement_theta_max',
                                      COL_EDIT).getRgb())

    def test_exptl_crystal_size(self):
        self.assertEqual('0.220',
                         self.cell_text('_exptl_crystal_size_max', COL_DATA))
        self.assertEqual('0.100',
                         self.cell_text('_exptl_crystal_size_mid', COL_DATA))
        self.assertEqual('0.040',
                         self.cell_text('_exptl_crystal_size_min', COL_DATA))

    def test_symmetry(self):
        self.assertEqual('18', self.cell_text('_space_group_IT_number', 0))
        self.assertEqual('orthorhombic',
                         self.cell_text('_space_group_crystal_system', 0))
        self.assertEqual('P 21 21 2',
                         self.cell_text('_space_group_name_H-M_alt', 0))
        self.assertEqual('P 2 2ab', self.cell_text('_space_group_name_Hall',
                                                   0))

    def test_abs_configuration(self):
        self.assertEqual(
            '?', self.cell_text('_chemical_absolute_configuration', COL_CIF))
        self.assertEqual(
            '', self.cell_text('_chemical_absolute_configuration', COL_DATA))
        self.assertEqual(
            '', self.cell_text('_chemical_absolute_configuration', COL_EDIT))
        self.assertEqual(
            yellow,
            self.myapp.ui.cif_main_table.itemFromKey(
                '_chemical_absolute_configuration', 1).background().color())

    def allrows_test_key(self, key: str = '', results: list = None):
        # The results list is a list with three items for each data column in the main table.
        self.myapp.hide()
        for n, r in enumerate(results):
            # print(self.cell_text(key, n))
            self.assertEqual(r, self.cell_text(key, n))

    def test_equipment_click_machine(self):
        self.equipment_click('APEX2 QUAZAR')
        self.allrows_test_key('_diffrn_measurement_method',
                              ['?', 'ω and ϕ scans', 'ω and ϕ scans'])
        self.allrows_test_key(
            '_diffrn_measurement_specimen_support',
            ['?', 'MiTeGen micromount', 'MiTeGen micromount'])

    # unittest.SkipTest('')
    def test_equipment_click_machine_oxford_0(self):
        self.equipment_click('APEX2 QUAZAR')
        # We have a value which is new. So a row at start is created and only the CIF column is populated
        self.assertEqual(
            '?',
            self.cell_text('_olex2_diffrn_ambient_temperature_device',
                           COL_CIF))

    def test_equipment_click_machine_oxford_1(self):
        self.equipment_click('APEX2 QUAZAR')
        self.assertEqual(
            'Oxford Cryostream 800',
            self.cell_text('_olex2_diffrn_ambient_temperature_device',
                           COL_DATA))

    def test_equipment_click_machine_oxford_2(self):
        self.equipment_click('APEX2 QUAZAR')
        self.assertEqual(
            'Oxford Cryostream 800',
            self.cell_text('_olex2_diffrn_ambient_temperature_device',
                           COL_EDIT))

    def test_equipment_click_author_address_0(self):
        # Check if click on author adds the address to second and third column:
        self.equipment_click('Crystallographer Details')
        self.assertEqual(
            '?', self.cell_text('_audit_contact_author_address', COL_CIF))

    def test_equipment_click_author_address_1(self):
        self.equipment_click('Crystallographer Details')
        self.assertEqual(
            unify_line_endings(addr),
            self.cell_text('_audit_contact_author_address', COL_DATA))

    def test_equipment_click_author_address_2(self):
        self.equipment_click('Crystallographer Details')
        self.assertEqual(
            unify_line_endings(addr),
            self.cell_text('_audit_contact_author_address', COL_EDIT))

    def test_contact_author_name_0(self):
        self.equipment_click('Crystallographer Details')
        self.assertEqual('?',
                         self.cell_text('_audit_contact_author_name', COL_CIF))

    def test_contact_author_name_1(self):
        self.equipment_click('Crystallographer Details')
        self.assertEqual(
            'Dr. Daniel Kratzert',
            self.cell_text('_audit_contact_author_name', COL_DATA))

    def test_contact_author_name_2(self):
        self.equipment_click('Crystallographer Details')
        self.assertEqual(
            'Dr. Daniel Kratzert',
            self.cell_text('_audit_contact_author_name', COL_EDIT))

    def test_contact_author_cellwidget_bevore_click(self):
        self.assertEqual(self.myapp.ui.cif_main_table.vheaderitems[5],
                         '_audit_contact_author_name')
        self.assertEqual('', self.myapp.ui.cif_main_table.getText(5, COL_DATA))

    def test_contact_author_cellwidget_after(self):
        self.equipment_click('Crystallographer Details')
        self.assertEqual(self.myapp.ui.cif_main_table.vheaderitems[5],
                         '_audit_contact_author_name')
        self.assertEqual('Dr. Daniel Kratzert',
                         self.myapp.ui.cif_main_table.getText(5, COL_DATA))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(5, COL_CIF))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(5, COL_DATA))
        self.assertEqual("<class 'NoneType'>",
                         self.cell_widget_class(5, COL_EDIT))

    def test_addr_after_author_click(self):
        self.assertNotEqual(
            unify_line_endings(addr),
            self.cell_text('_audit_contact_author_address', COL_EDIT))
        self.equipment_click('Crystallographer Details')
        self.assertEqual(
            unify_line_endings(addr),
            self.cell_text('_audit_contact_author_address', COL_EDIT))
        self.assertEqual(
            unify_line_endings(addr),
            self.cell_text('_audit_contact_author_address', COL_DATA))
        self.assertEqual(
            '?', self.cell_text('_audit_contact_author_address', COL_CIF))

    def test_edit_values_and_save(self):
        self.myapp.hide()
        self.myapp.ui.cif_main_table.setText(
            key='_atom_sites_solution_primary', column=2, txt='test1ä')
        self.myapp.ui.cif_main_table.setText(
            key='_atom_sites_solution_secondary', column=2, txt='test2ö')
        self.myapp.ui.cif_main_table.setText(
            key='_audit_contact_author_address', column=2, txt='test3ü')
        self.myapp.ui.cif_main_table.setText(key='_audit_contact_author_email',
                                             column=2,
                                             txt='test4ß')
        self.myapp.ui.cif_main_table.setText(key='_diffrn_measurement_method',
                                             column=2,
                                             txt='test 12 Å')
        cif = Path('testcif_file.cif')
        self.myapp.save_current_cif_file(cif.name)
        self.myapp.ui.cif_main_table.setRowCount(0)
        self.myapp.load_cif_file(cif)
        # test if data is still the same:
        # The character is quoted in the cif file:
        self.assertEqual(r'test 12 \%A',
                         self.myapp.cif['_diffrn_measurement_method'])
        # And unquoted in the application:
        self.assertEqual(
            r'test 12 Å',
            self.cell_text(key='_diffrn_measurement_method', col=0))
        self.assertEqual(
            'test1ä', self.cell_text(key='_atom_sites_solution_primary',
                                     col=0))
        self.assertEqual(r'test1a\"',
                         self.myapp.cif['_atom_sites_solution_primary'])
        self.assertEqual(
            'test2ö',
            self.cell_text(key='_atom_sites_solution_secondary', col=0))
        self.assertEqual(
            'test3ü', self.cell_text(key='_audit_contact_author_address',
                                     col=0))
        self.assertEqual(
            'test4ß', self.cell_text(key='_audit_contact_author_email', col=0))

    def test_rename_data_tag(self):
        self.myapp.hide()
        self.myapp.ui.datnameLineEdit.setText('foo_bar_yes')
        self.myapp.ui.SaveCifButton.click()
        self.myapp.ui.BackPushButton.click()
        pair = self.myapp.cif.block.find_pair('_vrf_PLAT307_foo_bar_yes')
        erg = [
            '_vrf_PLAT307_foo_bar_yes',
            ';\r\nPROBLEM: Isolated Metal Atom found in Structure (Unusual) Ga1 Check\r\nRESPONSE: foobar\r\n;'
        ]
        erg = [x.replace("\n", "").replace("\r", "") for x in erg]
        pair = [x.replace("\n", "").replace("\r", "") for x in pair]
        self.assertEqual(erg, pair)
        self.myapp.final_cif_file_name.unlink()