Пример #1
0
 def test_browse_for_missing_prefixed(self):
     path = self.data_regions_path
     basedir = os.path.dirname(path)
     widget = self.create_widget(
         owcsvimport.OWCSVFileImport,
         stored_settings={
             "__version__":
             3,
             "_session_items_v2":
             [(PathItem.VarPath("basedir",
                                "this file does not exist.csv").as_dict(),
               self.data_regions_options.as_dict())]
         },
         env={"basedir": basedir})
     widget.activate_recent(0)
     dlg = widget.findChild(QFileDialog)
     assert dlg is not None
     # calling selectFile when using native (macOS) dialog does not have
     # an effect - at least not immediately;
     dlg.setOption(QFileDialog.DontUseNativeDialog)
     dlg.selectFile(path)
     dlg.accept()
     cur = widget.current_item()
     self.assertTrue(samepath(path, cur.path()))
     self.assertEqual(cur.varPath(),
                      PathItem.VarPath("basedir", "data-regions.tab"))
     self.assertEqual(self.data_regions_options.as_dict(),
                      cur.options().as_dict())
Пример #2
0
    def test_model(self):
        path = TestOWCSVFileImport.data_regions_path
        model = owcsvimport.VarPathItemModel()
        model.setItemPrototype(owcsvimport.ImportItem())
        it1 = owcsvimport.ImportItem()
        it1.setVarPath(PathItem.VarPath("prefix", "data-regions.tab"))
        it2 = owcsvimport.ImportItem()
        it2.setVarPath(PathItem.AbsPath(path))
        model.appendRow([it1])
        model.appendRow([it2])

        def data(row, role):
            return model.data(model.index(row, 0), role)

        self.assertIsInstance(data(0, Qt.DecorationRole), QIcon)
        self.assertIsInstance(data(1, Qt.DecorationRole), QIcon)

        self.assertEqual(data(0, Qt.DisplayRole), "data-regions.tab")
        self.assertEqual(data(1, Qt.DisplayRole), "data-regions.tab")

        self.assertEqual(data(0, Qt.ToolTipRole),
                         "${prefix}/data-regions.tab (missing)")
        self.assertTrue(samepath(data(1, Qt.ToolTipRole), path))

        self.assertIsNotNone(data(0, Qt.ForegroundRole))
        self.assertIsNone(data(1, Qt.ForegroundRole))
        spy = QSignalSpy(model.dataChanged)
        model.setReplacementEnv({"prefix": os.path.dirname(path)})
        self.assertSequenceEqual(
            [[model.index(0, 0), model.index(1, 0), []]], list(spy))
        self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab")
        self.assertIsNone(data(0, Qt.ForegroundRole))
Пример #3
0
 def test_restore_from_local(self):
     dirname = os.path.dirname(__file__)
     path = os.path.join(dirname, "data-regions.tab")
     s = owcsvimport.OWCSVFileImport._local_settings()
     s.clear()
     QSettings_writeArray(
         s, "recent",
         [{
             "path": path,
             "options": json.dumps(self.data_regions_options.as_dict())
         }])
     w = self.create_widget(owcsvimport.OWCSVFileImport, )
     item = w.current_item()
     self.assertIsNone(item)
     simulate.combobox_activate_index(w.recent_combo, 0)
     item = w.current_item()
     self.assertTrue(samepath(item.path(), path))
     self.assertEqual(item.options(), self.data_regions_options)
     data = w.settingsHandler.pack_data(w)
     self.assertEqual(
         data['_session_items_v2'],
         [(PathItem.AbsPath(path).as_dict(),
           self.data_regions_options.as_dict())],
         "local settings item must be recorded in _session_items_v2 when "
         "activated",
     )
     self._check_data_regions(self.get_output("Data", w))
Пример #4
0
 def test_browse(self):
     widget = self.widget
     path = self.data_regions_path
     with self._browse_setup(widget, path):
         widget.browse()
     cur = widget.current_item()
     self.assertIsNotNone(cur)
     self.assertTrue(samepath(cur.path(), path))
Пример #5
0
    def test_browse_prefix(self):
        widget = self.widget
        path = self.data_regions_path
        with self._browse_setup(widget, path):
            basedir = os.path.dirname(__file__)
            widget.workflowEnv = lambda: {"basedir": basedir}
            widget.workflowEnvChanged("basedir", basedir, "")
            widget.browse_relative(prefixname="basedir")

        cur = widget.current_item()
        self.assertIsNotNone(cur)
        self.assertTrue(samepath(cur.path(), path))
        self.assertIsInstance(cur.varPath(), PathItem.VarPath)
Пример #6
0
    def test_restore(self):
        dirname = os.path.dirname(__file__)
        path = os.path.join(dirname, "data-regions.tab")

        w = self.create_widget(owcsvimport.OWCSVFileImport,
                               stored_settings={
                                   "_session_items":
                                   [(path, self.data_regions_options.as_dict())
                                    ]
                               })
        item = w.current_item()
        self.assertTrue(samepath(item.path(), path))
        self.assertEqual(item.options(), self.data_regions_options)
        out = self.get_output("Data", w)
        self._check_data_regions(out)
        self.assertEqual(out.name, "data-regions")
Пример #7
0
 def test_browse_for_missing(self):
     missing = os.path.dirname(__file__) + "/this file does not exist.csv"
     widget = self.create_widget(owcsvimport.OWCSVFileImport,
                                 stored_settings={
                                     "_session_items":
                                     [(missing,
                                       self.data_regions_options.as_dict())]
                                 })
     widget.activate_recent(0)
     dlg = widget.findChild(QFileDialog)
     assert dlg is not None
     # calling selectFile when using native (macOS) dialog does not have
     # an effect - at least not immediately;
     dlg.setOption(QFileDialog.DontUseNativeDialog)
     dlg.selectFile(self.data_regions_path)
     dlg.accept()
     cur = widget.current_item()
     self.assertTrue(samepath(self.data_regions_path, cur.path()))
     self.assertEqual(self.data_regions_options.as_dict(),
                      cur.options().as_dict())