Fix tests

This commit is contained in:
Andras Schmelczer 2022-05-25 19:49:14 +02:00
parent 3b6134de2e
commit 2d71fceb54
18 changed files with 14 additions and 16 deletions

View file

@ -35,6 +35,7 @@ install_requires =
langcodes[data] >= 3.3.0 langcodes[data] >= 3.3.0
segtok >= 1.5.11 segtok >= 1.5.11
langdetect >= 1.0.9 langdetect >= 1.0.9
pyaml >= 21.0.0
[options.package_data] [options.package_data]
* = *.json, *.yaml, *.yml * = *.json, *.yaml, *.yml

View file

@ -2,20 +2,20 @@
import re import re
from importlib import import_module from importlib import import_module
from sys import argv from sys import argv
import uvicorn import uvicorn
from uvicorn.config import LOGGING_CONFIG from uvicorn.config import LOGGING_CONFIG
from .great_ai.exceptions import MissingArgumentError
from .great_ai.context import get_context from .great_ai.context import get_context
from .great_ai.exceptions import MissingArgumentError
def main() -> None:
def main():
if len(argv) < 2: if len(argv) < 2:
raise MissingArgumentError(f"Provide a filename such as: {argv[0]} my_app.py") raise MissingArgumentError(f"Provide a filename such as: {argv[0]} my_app.py")
module_name = re.sub(r"\.py\b", "", argv[1]) module_name = re.sub(r"\.py\b", "", argv[1])
base = module_name.split(":")[0] base = module_name.split(":")[0]
import_module(base) import_module(base)
@ -25,7 +25,7 @@ def main():
module_name += ":app" module_name += ":app"
get_context().logger.warning( get_context().logger.warning(
'Service name (name of variable) is assumed to be "app",' 'Service name (name of variable) is assumed to be "app",'
+ ' such as: `app = create_service(predict_domain)`' + " such as: `app = create_service(predict_domain)`"
) )
uvicorn.run( uvicorn.run(
@ -50,6 +50,7 @@ def main():
}, },
) )
if __name__ == "__main__": if __name__ == "__main__":
try: try:
main() main()

View file

@ -9,6 +9,7 @@ from .logger import create_logger
logger = create_logger("parallel_map") logger = create_logger("parallel_map")
def parallel_map( def parallel_map(
function: Callable[[Any], Any], function: Callable[[Any], Any],
values: Iterable[Any], values: Iterable[Any],
@ -27,7 +28,7 @@ def parallel_map(
logger.info( logger.info(
f"Starting parallel map, concurrency: {concurrency}, chunk size: {chunk_size}" f"Starting parallel map, concurrency: {concurrency}, chunk size: {chunk_size}"
) )
if concurrency == 1 or len(values) <= chunk_size: if concurrency == 1 or len(values) <= chunk_size:
logger.warning(f"Running in series, there is no reason for parallelism") logger.warning(f"Running in series, there is no reason for parallelism")
iterable = values if disable_progress else tqdm(values) iterable = values if disable_progress else tqdm(values)

View file

@ -6,7 +6,6 @@ from typing import Any, List, Optional, Pattern, Tuple, Union
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from bs4.element import NavigableString, Tag from bs4.element import NavigableString, Tag
from sus.publication_tei.models.element import Paragraph
from ..clean import clean from ..clean import clean
from ..lemmatize_text import lemmatize_text from ..lemmatize_text import lemmatize_text
@ -20,6 +19,7 @@ from .models import (
Element, Element,
Meta, Meta,
MetaType, MetaType,
Paragraph,
PublicationMetadata, PublicationMetadata,
Text, Text,
Title, Title,
@ -30,8 +30,8 @@ THIS_FOLDER = Path(os.path.dirname(os.path.abspath(__file__)))
class PublicationTEI: class PublicationTEI:
# remove template sentenaces, such as copyright notices # remove template sentences, such as copyright notices
agressive_cleaning_enabled = True aggressive_cleaning_enabled = True
def __init__(self, tei: str): def __init__(self, tei: str):
self._document_order_counter = 0 self._document_order_counter = 0
@ -324,7 +324,7 @@ class PublicationTEI:
if text is None: if text is None:
return None return None
if self.agressive_cleaning_enabled: if self.aggressive_cleaning_enabled:
filtered = filter_sentences( filtered = filter_sentences(
text, text,
THIS_FOLDER / "templates.yaml", THIS_FOLDER / "templates.yaml",

View file

@ -1,4 +1,4 @@
from sus.publication_tei.models import ( from great_ai.utilities.publication_tei.models import (
Affiliation, Affiliation,
Author, Author,
Bookmark, Bookmark,

View file

@ -3,7 +3,6 @@ import unittest
from src.great_ai.utilities.clean import clean from src.great_ai.utilities.clean import clean
class TestClean(unittest.TestCase): class TestClean(unittest.TestCase):
def test_xml_handling(self) -> None: def test_xml_handling(self) -> None:
xml = '<strong>Hi, </strong> my name<br/>is <span style="color: hotpink;"> András</span>! &lt;&#51; <> < ></><> &lt;&gt; <|' xml = '<strong>Hi, </strong> my name<br/>is <span style="color: hotpink;"> András</span>! &lt;&#51; <> < ></><> &lt;&gt; <|'

View file

@ -3,7 +3,6 @@ import unittest
from src.great_ai.utilities.get_sentences import get_sentences from src.great_ai.utilities.get_sentences import get_sentences
class TestGetSentences(unittest.TestCase): class TestGetSentences(unittest.TestCase):
def test_default(self) -> None: def test_default(self) -> None:
text = "This is a complete sentence. So is this. However this is n" # ot. text = "This is a complete sentence. So is this. However this is n" # ot.

View file

@ -3,7 +3,6 @@ import unittest
from src.great_ai.utilities.match_names.match_names import match_names from src.great_ai.utilities.match_names.match_names import match_names
class TestMatchNames(unittest.TestCase): class TestMatchNames(unittest.TestCase):
def test_grid(self) -> None: def test_grid(self) -> None:
names = [ names = [

View file

@ -3,7 +3,6 @@ from pathlib import Path
from src.great_ai.utilities.publication_tei import PublicationTEI from src.great_ai.utilities.publication_tei import PublicationTEI
from .data.parsed import ( from .data.parsed import (
abstract, abstract,
authors, authors,

View file

@ -2,7 +2,6 @@ import unittest
from src.great_ai.utilities.unique import unique from src.great_ai.utilities.unique import unique
original = [ original = [
("a", 1), ("a", 1),
("b", 5), ("b", 5),