def test_udpipe_local_models(self): """Test if UDPipe works offline and uses local models""" models = UDPipeModels() [models.localfiles.remove(f[0]) for f in models.localfiles.listfiles()] _ = models['Slovenian'] with mock.patch('serverfiles.ServerFiles.listfiles', **{'side_effect': ConnectionError()}): self.assertIn('Slovenian', UDPipeModels().supported_languages) self.assertEqual(1, len(UDPipeModels().supported_languages))
def __init__(self, master): super().__init__(master) label = gui.label(self, self, 'Language:') label.setAlignment(Qt.AlignRight) self.method_layout.addWidget(label, self.SNOWBALL, 1) snowball_box = widgets.ComboBox(self, 'snowball_language', items=preprocess.SnowballStemmer.supported_languages) snowball_box.currentIndexChanged.connect(self.change_language) self.method_layout.addWidget(snowball_box, self.SNOWBALL, 2) self.methods[self.SNOWBALL].language = self.snowball_language self.udpipe_tokenizer_box = QCheckBox("UDPipe tokenizer", self, checked=self.udpipe_tokenizer) self.udpipe_tokenizer_box.stateChanged.connect(self.change_tokenizer) self.method_layout.addWidget(self.udpipe_tokenizer_box, self.UDPIPE, 1) self.udpipe_label = gui.label(self, self, 'Language:') self.udpipe_label.setAlignment(Qt.AlignRight) self.method_layout.addWidget(self.udpipe_label, self.UDPIPE, 2) self.udpipe_models = UDPipeModels() self.create_udpipe_box() self.udpipe_online = self.udpipe_models.online self.on_off_button.stateChanged.connect(self.check_udpipe_online) self.check_udpipe_online() self.methods[self.UDPIPE].language = self.udpipe_language self.methods[self.UDPIPE].use_tokenizer = self.udpipe_tokenizer
def test_udpipe_model(self): """Test udpipe models loading from server""" models = UDPipeModels() self.assertIn('Slovenian', models.supported_languages) self.assertEqual(68, len(models.supported_languages)) local_file = os.path.join(models.local_data, 'slovenian-ud-2.0-170801.udpipe') model = models['Slovenian'] self.assertEqual(model, local_file) self.assertTrue(os.path.isfile(local_file))
def test_udpipe_offline(self): """Test if UDPipe works offline""" self.assertTrue(UDPipeModels().online) with mock.patch('serverfiles.ServerFiles.listfiles', **{'side_effect': ConnectionError()}): self.assertFalse(UDPipeModels().online)