def addCorpus(self, corpus, *args, **kwargs): if corpus == "wauchier": corpus = add_corpus("wauchier", db, *args, **kwargs) else: corpus = add_corpus("floovant", db, *args, **kwargs) self.driver.get(self.get_server_url()) if self.AUTO_LOG_IN and not kwargs.get("no_corpus_user", False): self.addCorpusUser(corpus.name, self.app.config['ADMIN_EMAIL'], is_owner=kwargs.get("is_owner", True)) return corpus
def db_fixtures(): """ Loads demo/tests data to the database """ with app.app_context(): from tests.db_fixtures import add_corpus add_corpus( "wauchier", db, with_token=True, tokens_up_to=None, with_allowed_lemma=True, partial_allowed_lemma=False, with_allowed_pos=True, partial_allowed_pos=False, with_allowed_morph=True) add_corpus( "floovant", db, with_token=True, tokens_up_to=None, with_allowed_lemma=True, partial_allowed_lemma=False, with_allowed_pos=True, partial_allowed_pos=False, with_allowed_morph=True) click.echo("Loaded fixtures to the database")
def test_corpus_dump(self): """ Test that data export works correctly """ # Ingest data this way, not the best practice, but the shortest. Will allow file comparison down the lane with self.app.app_context(): add_corpus("floovant", db, tokens_up_to=3, with_allowed_lemma=True, partial_allowed_lemma=True, with_allowed_morph=True, partial_allowed_morph=True, with_allowed_pos=True, partial_allowed_pos=True) with self.runner.isolated_filesystem() as f: curr_dir = str(f) test_dir = "some_dir" result = self.invoke("corpus-dump", "2", "--path", test_dir) self.assertHasContents( os.path.join(curr_dir, test_dir, "tokens.csv").replace("\r", ""), "token_id form lemma POS morph\n" "1 SOIGNORS seignor _ NOMB.=p|GENRE=m|CAS=n\n" "2 or or4 _ DEGRE=-\n" "3 escoutez escouter _ MODE=imp|PERS.=2|NOMB.=p\n") self.assertIn("--- Tokens dumped", result.output) self.assertHasContents( os.path.join(curr_dir, test_dir, "allowed_lemma.txt"), "escouter\nor4\nseignor") self.assertIn("--- Allowed Lemma Values dumped", result.output) self.assertHasContents( os.path.join(curr_dir, test_dir, "allowed_pos.txt"), "ADVgen,VERcjg,NOMcom") self.assertIn("--- Allowed POS Values dumped", result.output) self.assertHasContents( os.path.join(curr_dir, test_dir, "allowed_morph.csv").replace("\r", ""), "label readable\n" "_ pas de morphologie\n" "DEGRE=- non applicable\n" "MODE=imp|PERS.=2|NOMB.=p impératif 2e personne pluriel\n") self.assertIn("--- Allowed Morphological Values dumped", result.output)
def addCorpus(self, corpus, *args, **kwargs): corpus = add_corpus(corpus.lower(), db, *args, **kwargs) if self.AUTO_LOG_IN and not kwargs.get("no_corpus_user", False): self.addCorpusUser(corpus.name, self.app.config['ADMIN_EMAIL'], is_owner=kwargs.get("is_owner", True)) self.driver.get(self.get_server_url()) return corpus
def test_corpus_dump_not_found(self): """ Test that data export works correctly by not raising an issue if Corpus does not exist """ # Ingest data this way, not the best practice, but the shortest. Will allow file comparison down the lane with self.app.app_context(): add_corpus("floovant", db, tokens_up_to=3, with_allowed_lemma=True, partial_allowed_lemma=True, with_allowed_morph=True, partial_allowed_morph=True, with_allowed_pos=True, partial_allowed_pos=True) with self.runner.isolated_filesystem() as f: curr_dir = str(f) test_dir = "some_dir" result = self.invoke("corpus-dump", "1", "--path", test_dir) self.assertIn("Corpus not found", result.output) self.assertEqual(len(os.listdir(os.path.join(curr_dir, test_dir))), 0, "There should be no files")
def test_corpus_list(self): with self.app.app_context(): add_corpus("floovant", db, tokens_up_to=3, with_allowed_lemma=True, partial_allowed_lemma=True, with_allowed_morph=True, partial_allowed_morph=True, with_allowed_pos=True, partial_allowed_pos=True) add_corpus("wauchier", db, tokens_up_to=3, with_allowed_lemma=True, partial_allowed_lemma=True, with_allowed_morph=True, partial_allowed_morph=True, with_allowed_pos=True, partial_allowed_pos=True) result = self.invoke("corpus-list") self.assertIn("1\t| Wauchier", result.output) self.assertIn("2\t| Floovant", result.output)
def addCorpus(self, corpus, *args, **kwargs): if corpus == "wauchier": add_corpus("wauchier", db, *args, **kwargs) else: add_corpus("floovant", db, *args, **kwargs)