Exemplo n.º 1
0
    def test_set_parameters(self):
        sw_path = RecentPath.create("Foo", [])
        lx_path = RecentPath.create("Bar", [])
        params = {"methods": [FilteringModule.Lexicon, FilteringModule.Regexp],
                  "language": "Finnish",
                  "sw_path": sw_path, "lx_path": lx_path,
                  "sw_list": [sw_path], "lx_list": [lx_path],
                  "pattern": "foo", "start": 0.2, "end": 0.7, "n_tokens": 10,
                  "invalidated": False}
        self.editor.setParameters(params)
        self.assertDictEqual(self.editor.parameters(), params)

        check_boxes = self.check_boxes
        self.assertFalse(check_boxes[0].isChecked())
        self.assertTrue(check_boxes[1].isChecked())
        self.assertTrue(check_boxes[2].isChecked())
        self.assertFalse(check_boxes[3].isChecked())
        self.assertFalse(check_boxes[4].isChecked())

        self.assertEqual(self.combo.currentText(), "Finnish")
        self.assertEqual(self.sw_combo.currentText(), "Foo")
        self.assertEqual(self.lx_combo.currentText(), "Bar")
        self.assertEqual(self.line_edit.text(), "foo")
        self.assertEqual(self.spins[0].value(), 0.2)
        self.assertEqual(self.spins[1].value(), 0.7)
        self.assertEqual(self.spin.value(), 10)
 def test_resolve(self):
     temp_file = NamedTemporaryFile(dir=os.getcwd(), delete=False)
     file_name = temp_file.name
     temp_file.close()
     base_name = os.path.basename(file_name)
     try:
         recent_path = RecentPath(os.path.join("temp/datasets", base_name),
                                  "", os.path.join("datasets", base_name))
         search_paths = [("basedir", os.getcwd())]
         self.assertIsNotNone(recent_path.resolve(search_paths))
     finally:
         os.remove(file_name)
Exemplo n.º 3
0
    def __relocate_file(self, path: RecentPath) -> RecentPath:
        basedir = self.workflowEnv().get("basedir", None)
        if basedir is None or path is None:
            return path

        search_paths = [("basedir", basedir)]
        resolved = path.resolve(search_paths)
        kwargs = dict(title=path.title, sheet=path.sheet,
                      file_format=path.file_format)
        if resolved is not None:
            return RecentPath.create(resolved.abspath, search_paths, **kwargs)
        elif path.search(search_paths) is not None:
            return RecentPath.create(path.search(search_paths),
                                     search_paths, **kwargs)
        return path
 def test_open_moved_workflow(self, load):
     """
     Test opening workflow that has been moved to another location
     (i.e. sent by email), considering data file is stored in the same
     directory as the workflow.
     """
     temp_file = NamedTemporaryFile(dir=os.getcwd(), delete=False)
     file_name = temp_file.name
     temp_file.close()
     base_name = os.path.basename(file_name)
     try:
         recent_path = RecentPath(os.path.join("temp/models", base_name),
                                  "", os.path.join("models", base_name))
         stored_settings = {"recent_paths": [recent_path]}
         w = self.create_widget(OWLoadModel,
                                stored_settings=stored_settings)
         w.open_file()
         self.assertEqual(w.file_combo.count(), 1)
         args = load.call_args[0][0]
         self.assertEqual(args.name, file_name.replace("\\", "/"))
     finally:
         os.remove(file_name)
Exemplo n.º 5
0
 def add_path(self, filename: str):
     recent = RecentPath.create(filename, [])
     if recent in self.recent_paths:
         self.recent_paths.remove(recent)
     self.recent_paths.insert(0, recent)
     self.set_file_list()
Exemplo n.º 6
0
 def str_into_paths(label):
     files = [
         RecentPath.create(path, [])
         for path in filters[label] if path != _DEFAULT_NONE
     ]
     return files[0] if files else None, files