Refactor and reformat

This commit is contained in:
Andras Schmelczer 2022-06-25 11:06:04 +02:00
parent 7682f3036c
commit 5046b1c5a0
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
23 changed files with 122 additions and 71 deletions

View file

@ -1,6 +1,6 @@
zeroth_key="test"
first_key=test
first_key= András
second_key = test 2 # comment is ignored
third_key= "test= 2=="

View file

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

View file

@ -1,6 +1,6 @@
import unittest
from src.great_ai.utilities.clean import clean
from src.great_ai.utilities import clean
class TestClean(unittest.TestCase):

View file

@ -1,7 +1,9 @@
import unittest
from pathlib import Path
import pytest
from src.great_ai.utilities.config_file import ConfigFile
from src.great_ai.utilities import ConfigFile
DATA_PATH = Path(__file__).parent.resolve() / "data"
@ -9,38 +11,60 @@ DATA_PATH = Path(__file__).parent.resolve() / "data"
class TestConfigFile(unittest.TestCase):
def test_simple(self) -> None:
c = ConfigFile(DATA_PATH / "good.conf")
assert c.zeroth_key == 'test'
assert c.first_key == 'test'
assert c.second_key == 'test 2'
assert c.third_key == 'test= 2=='
assert c.fourth_key == '''
assert c.zeroth_key == "test"
assert c.first_key == "András"
assert c.second_key == "test 2"
assert c.third_key == "test= 2=="
assert (
c.fourth_key
== """
this#
is
multiline
'''
assert c.whitespace == 'hardly matters'
"""
)
assert c.whitespace == "hardly matters"
def test_simple_dict(self) -> None:
c = ConfigFile(DATA_PATH / "good.conf")
assert c["zeroth_key"] == "test"
assert c["first_key"] == "András"
assert c["second_key"] == "test 2"
assert c["third_key"] == "test= 2=="
assert (
c["fourth_key"]
== """
this#
is
multiline
"""
)
assert c["whitespace"] == "hardly matters"
def test_string_path(self) -> None:
c = ConfigFile(str(DATA_PATH / "good.conf"))
assert c.zeroth_key == 'test'
assert c.first_key == 'test'
assert c.second_key == 'test 2'
assert c.third_key == 'test= 2=='
assert c.fourth_key == '''
assert c.zeroth_key == "test"
assert c.first_key == "András"
assert c.second_key == "test 2"
assert c.third_key == "test= 2=="
assert (
c.fourth_key
== """
this#
is
multiline
'''
assert c.whitespace == 'hardly matters'
"""
)
assert c.whitespace == "hardly matters"
def test_env(self) -> None:
import os
os.environ['alma'] = '12'
os.environ["alma"] = "12"
c = ConfigFile(DATA_PATH / "env.conf")
del os.environ['alma']
assert c.first_key == 'test'
assert c.second_key == '12'
del os.environ["alma"]
assert c.first_key == "test"
assert c.second_key == "12"
def test_env_not_exists(self) -> None:
with pytest.raises(KeyError):
@ -48,9 +72,10 @@ multiline
def test_env_not_exists_but_ignored(self) -> None:
with pytest.raises(KeyError):
ConfigFile(DATA_PATH / "env.conf", ignore_missing_environment_variables=True)
ConfigFile(
DATA_PATH / "env.conf", ignore_missing_environment_variables=True
)
def test_duplicate_key(self) -> None:
with pytest.raises(KeyError):
ConfigFile(DATA_PATH / "bad.conf")

View file

@ -5,7 +5,7 @@ import matplotlib
matplotlib.use("Agg") # don't show a window for each test
from src.great_ai.utilities.evaluate_ranking import evaluate_ranking
from src.great_ai.utilities import evaluate_ranking
class TestEvaluateRanking(unittest.TestCase):

View file

@ -1,6 +1,6 @@
import unittest
from src.great_ai.utilities.get_sentences import get_sentences
from src.great_ai.utilities import get_sentences
class TestGetSentences(unittest.TestCase):

View file

@ -1,6 +1,6 @@
import unittest
from src.great_ai.utilities.language import (
from src.great_ai.utilities import (
english_name_of_language,
is_english,
predict_language,

View file

@ -1,6 +1,6 @@
import unittest
from src.great_ai.utilities.lemmatize_text import lemmatize_text
from src.great_ai.utilities import lemmatize_text
class TestLemmatizeText(unittest.TestCase):

View file

@ -1,7 +1,6 @@
import unittest
from src.great_ai.utilities.lemmatize_text import lemmatize_token
from src.great_ai.utilities.nlp import nlp
from src.great_ai.utilities import lemmatize_token, nlp
class TestLemmatizeToken(unittest.TestCase):

View file

@ -1,6 +1,6 @@
import unittest
from src.great_ai.utilities.match_names.match_names import match_names
from src.great_ai.utilities import match_names
class TestMatchNames(unittest.TestCase):

View file

@ -1,6 +1,6 @@
import unittest
from src.great_ai.utilities.parallel_map import parallel_map
from src.great_ai.utilities import parallel_map
COUNT = int(1e5) + 3

View file

@ -1,7 +1,7 @@
import unittest
from pathlib import Path
from src.great_ai.utilities.publication_tei import PublicationTEI
from src.great_ai.utilities import PublicationTEI
from .data.parsed import (
abstract,

View file

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