def setUp(self): self.editor = FilteringModule()
class TestFilterModule(WidgetTest): def setUp(self): self.editor = FilteringModule() @property def check_boxes(self): return [cb for i, cb in self.editor._MultipleMethodModule__cbs] @property def combo(self): return self.editor._FilteringModule__combo @property def sw_combo(self): return self.editor._FilteringModule__sw_loader.file_combo @property def lx_combo(self): return self.editor._FilteringModule__lx_loader.file_combo @property def line_edit(self): return self.editor._FilteringModule__edit @property def group_buttons(self): return self.editor._FilteringModule__freq_group.buttons() @property def rel_spins(self): return self.editor._FilteringModule__rel_range_spins.spins() @property def abs_spins(self): return self.editor._FilteringModule__abs_range_spins.spins() @property def spin(self): return self.editor._FilteringModule__spin_n def test_init(self): check_boxes = self.check_boxes self.assertTrue(check_boxes[0].isChecked()) self.assertGreater(len(check_boxes[0].toolTip()), 0) for i in range(1, len(check_boxes)): self.assertFalse(check_boxes[i].isChecked()) self.assertGreater(len(check_boxes[i].toolTip()), 0) self.assertEqual(self.combo.currentText(), "English") self.assertEqual(self.sw_combo.currentText(), "(none)") self.assertEqual(self.lx_combo.currentText(), "(none)") self.assertEqual(self.line_edit.text(), FilteringModule.DEFAULT_PATTERN) self.assertTrue(self.group_buttons[0].isChecked()) self.assertFalse(self.group_buttons[1].isChecked()) self.assertEqual(self.rel_spins[0].value(), 0.1) self.assertEqual(self.rel_spins[1].value(), 0.9) self.assertEqual(self.abs_spins[0].value(), 1) self.assertEqual(self.abs_spins[1].value(), 10) self.assertEqual(self.spin.value(), 100) def test_parameters(self): params = { "methods": [FilteringModule.Stopwords], "language": "English", "sw_path": None, "lx_path": None, "sw_list": [], "lx_list": [], "pattern": FilteringModule.DEFAULT_PATTERN, "freq_type": 0, "rel_start": 0.1, "rel_end": 0.9, "abs_start": 1, "abs_end": 10, "n_tokens": 100, "pos_tags": "NOUN,VERB", "invalidated": False } self.assertDictEqual(self.editor.parameters(), params) 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", "freq_type": 1, "rel_start": 0.2, "rel_end": 0.7, "abs_start": 2, "abs_end": 15, "n_tokens": 10, "pos_tags": "JJ", "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.assertFalse(self.group_buttons[0].isChecked()) self.assertTrue(self.group_buttons[1].isChecked()) self.assertEqual(self.rel_spins[0].value(), 0.2) self.assertEqual(self.rel_spins[1].value(), 0.7) self.assertEqual(self.abs_spins[0].value(), 2) self.assertEqual(self.abs_spins[1].value(), 15) self.assertEqual(self.spin.value(), 10) def test_createinstance(self): pp = self.editor.createinstance(self.editor.parameters()) self.assertIsInstance(pp[0], StopwordsFilter) params = { "methods": [FilteringModule.Stopwords, FilteringModule.MostFreq] } pp = self.editor.createinstance(params) self.assertIsInstance(pp[0], StopwordsFilter) self.assertIsInstance(pp[1], MostFrequentTokensFilter) def test_repr(self): self.assertEqual(str(self.editor), "Stopwords (Language: English, File: None)") params = {"methods": [FilteringModule.Lexicon, FilteringModule.Regexp]} self.editor.setParameters(params) self.assertEqual( str(self.editor), f"Lexicon (File: None), Regexp ({FilteringModule.DEFAULT_PATTERN})" )