Beispiel #1
0
 def setUp(self):
     self.sc = ScorerConverter(app)
Beispiel #2
0
 def setUp(self):
     self.sc = ScorerConverter(app)
Beispiel #3
0
class TestScorerConverter(unittest.TestCase):
    def setUp(self):
        self.sc = ScorerConverter(app)

    def test_initial_state(self):
        self.assertIsNone(self.sc.results_file)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(), ScorerConverter.status_text["select"])

    @patch("scorer_to_usebio.qt.get_default_filename", new=get_tmp_filename)
    def test_select_valid(self):
        filename = "examples/pairs.xml"

        def getOpenFileName(*args, **kwargs):
            return (filename, "")

        QtWidgets.QFileDialog.getOpenFileName = getOpenFileName

        QtTest.QTest.mouseClick(self.sc.selectButton, QtCore.Qt.LeftButton)
        self.assertEqual(self.sc.results_file, filename)
        self.assertTrue(self.sc.saved.name.endswith("16-11-2015-Monday_Afternoon_November_Pairs.xml"))
        self.assertTrue(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(), ScorerConverter.status_text["converted_ok"])
        self.assertTrue(self.sc.saved.exists())
        self.sc.saved.unlink()

    @patch("scorer_to_usebio.qt.get_default_filename", new=get_tmp_filename)
    def test_select_nonexistent(self):
        filename = "blah/nonexistent.xml"

        def getOpenFileName(*args, **kwargs):
            return (filename, "")

        QtWidgets.QFileDialog.getOpenFileName = getOpenFileName

        QtTest.QTest.mouseClick(self.sc.selectButton, QtCore.Qt.LeftButton)
        self.assertEqual(self.sc.results_file, filename)
        self.assertIsNone(self.sc.saved)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(), ScorerConverter.status_text["converted_error"])

    @patch("scorer_to_usebio.qt.get_default_filename", new=get_tmp_filename)
    def test_select_invalid(self):
        filename = "README.md"

        def getOpenFileName(*args, **kwargs):
            return (filename, "")

        QtWidgets.QFileDialog.getOpenFileName = getOpenFileName

        QtTest.QTest.mouseClick(self.sc.selectButton, QtCore.Qt.LeftButton)
        self.assertEqual(self.sc.results_file, filename)
        self.assertIsNone(self.sc.saved)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(), ScorerConverter.status_text["converted_error"])

    def test_delete(self):
        file = tempfile.NamedTemporaryFile(delete=False)
        file.close()
        path = Path(file.name)
        self.sc.saved = path
        self.assertTrue(path.exists())
        self.sc.deleteButton.setEnabled(True)
        QtTest.QTest.mouseClick(self.sc.deleteButton, QtCore.Qt.LeftButton)
        self.assertFalse(path.exists())
        self.assertIsNone(self.sc.saved)
        self.assertIsNone(self.sc.results_file)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(), ScorerConverter.status_text["deleted"])

    def test_delete_nonexistent(self):
        file = tempfile.NamedTemporaryFile()
        path = Path(file.name)
        file.close()
        self.assertFalse(path.exists())
        self.sc.saved = path
        self.sc.deleteButton.setEnabled(True)
        QtTest.QTest.mouseClick(self.sc.deleteButton, QtCore.Qt.LeftButton)
        self.assertFalse(path.exists())
        self.assertIsNone(self.sc.saved)
        self.assertIsNone(self.sc.results_file)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(), ScorerConverter.status_text["select"])

    @patch("scorer_to_usebio.qt.get_default_filename", new=get_tmp_filename)
    def test_set_output(self):
        dirname = "."

        def getExistingDirectory(*args, **kwargs):
            return dirname

        QtWidgets.QFileDialog.getExistingDirectory = getExistingDirectory

        QtTest.QTest.mouseClick(self.sc.outputButton, QtCore.Qt.LeftButton)

        self.assertEqual(self.sc.persistent.output_directory, dirname)
Beispiel #4
0
class TestScorerConverter(unittest.TestCase):
    def setUp(self):
        self.sc = ScorerConverter(app)

    def test_initial_state(self):
        self.assertIsNone(self.sc.results_file)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(),
                         ScorerConverter.status_text['select'])

    @patch('scorer_to_usebio.qt.get_default_filename', new=get_tmp_filename)
    def test_select_valid(self):
        filename = 'examples/pairs.xml'

        def getOpenFileName(*args, **kwargs):
            return (filename, "")

        QtWidgets.QFileDialog.getOpenFileName = getOpenFileName

        QtTest.QTest.mouseClick(self.sc.selectButton, QtCore.Qt.LeftButton)
        self.assertEqual(self.sc.results_file, filename)
        self.assertTrue(
            self.sc.saved.name.endswith(
                "16-11-2015-Monday_Afternoon_November_Pairs.xml"))
        self.assertTrue(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(),
                         ScorerConverter.status_text['converted_ok'])
        self.assertTrue(self.sc.saved.exists())
        self.sc.saved.unlink()

    @patch('scorer_to_usebio.qt.get_default_filename', new=get_tmp_filename)
    def test_select_nonexistent(self):
        filename = 'blah/nonexistent.xml'

        def getOpenFileName(*args, **kwargs):
            return (filename, "")

        QtWidgets.QFileDialog.getOpenFileName = getOpenFileName

        QtTest.QTest.mouseClick(self.sc.selectButton, QtCore.Qt.LeftButton)
        self.assertEqual(self.sc.results_file, filename)
        self.assertIsNone(self.sc.saved)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(),
                         ScorerConverter.status_text['converted_error'])

    @patch('scorer_to_usebio.qt.get_default_filename', new=get_tmp_filename)
    def test_select_invalid(self):
        filename = 'README.md'

        def getOpenFileName(*args, **kwargs):
            return (filename, "")

        QtWidgets.QFileDialog.getOpenFileName = getOpenFileName

        QtTest.QTest.mouseClick(self.sc.selectButton, QtCore.Qt.LeftButton)
        self.assertEqual(self.sc.results_file, filename)
        self.assertIsNone(self.sc.saved)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(),
                         ScorerConverter.status_text['converted_error'])

    def test_delete(self):
        file = tempfile.NamedTemporaryFile(delete=False)
        file.close()
        path = Path(file.name)
        self.sc.saved = path
        self.assertTrue(path.exists())
        self.sc.deleteButton.setEnabled(True)
        QtTest.QTest.mouseClick(self.sc.deleteButton, QtCore.Qt.LeftButton)
        self.assertFalse(path.exists())
        self.assertIsNone(self.sc.saved)
        self.assertIsNone(self.sc.results_file)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(),
                         ScorerConverter.status_text['deleted'])

    def test_delete_nonexistent(self):
        file = tempfile.NamedTemporaryFile()
        path = Path(file.name)
        file.close()
        self.assertFalse(path.exists())
        self.sc.saved = path
        self.sc.deleteButton.setEnabled(True)
        QtTest.QTest.mouseClick(self.sc.deleteButton, QtCore.Qt.LeftButton)
        self.assertFalse(path.exists())
        self.assertIsNone(self.sc.saved)
        self.assertIsNone(self.sc.results_file)
        self.assertFalse(self.sc.deleteButton.isEnabled())
        self.assertEqual(self.sc.statusBar().currentMessage(),
                         ScorerConverter.status_text['select'])

    @patch('scorer_to_usebio.qt.get_default_filename', new=get_tmp_filename)
    def test_set_output(self):
        dirname = '.'

        def getExistingDirectory(*args, **kwargs):
            return dirname

        QtWidgets.QFileDialog.getExistingDirectory = getExistingDirectory

        QtTest.QTest.mouseClick(self.sc.outputButton, QtCore.Qt.LeftButton)

        self.assertEqual(self.sc.persistent.output_directory, dirname)