Reformat asserts

This commit is contained in:
Andras Schmelczer 2022-06-25 10:39:31 +02:00
parent fcdd25c974
commit 2ee246d133
10 changed files with 77 additions and 77 deletions

View file

@ -5,22 +5,22 @@ from src.great_ai.large_file.helper import human_readable_to_byte
class TestHumanReadableToByte(unittest.TestCase):
def test_simple_cases(self) -> None:
self.assertEqual(human_readable_to_byte("1KB"), 1024)
self.assertEqual(human_readable_to_byte("2KB"), 2048)
assert human_readable_to_byte("1KB") == 1024
assert human_readable_to_byte("2KB") == 2048
def test_fractions(self) -> None:
self.assertEqual(human_readable_to_byte("0.5KB"), 512)
self.assertEqual(human_readable_to_byte("20.5KB"), 1024 * 20 + 512)
assert human_readable_to_byte("0.5KB") == 512
assert human_readable_to_byte("20.5KB") == 1024 * 20 + 512
def test_formating(self) -> None:
self.assertEqual(human_readable_to_byte(" 1MB"), 1024 * 1024)
self.assertEqual(human_readable_to_byte(" 2 MB"), 1024 * 1024 * 2)
self.assertEqual(human_readable_to_byte(" 4 MB "), 1024 * 1024 * 4)
self.assertEqual(human_readable_to_byte("8MB "), 1024 * 1024 * 8)
self.assertEqual(human_readable_to_byte(" 1.5 MB "), 1024 * 1024 * 1.5)
assert human_readable_to_byte(" 1MB") == 1024 * 1024
assert human_readable_to_byte(" 2 MB") == 1024 * 1024 * 2
assert human_readable_to_byte(" 4 MB ") == 1024 * 1024 * 4
assert human_readable_to_byte("8MB ") == 1024 * 1024 * 8
assert human_readable_to_byte(" 1.5 MB ") == 1024 * 1024 * 1.5
def test_casing(self) -> None:
self.assertEqual(human_readable_to_byte("0.5GB"), 0.5 * 1024 * 1024 * 1024)
self.assertEqual(human_readable_to_byte("0.5gB"), 0.5 * 1024 * 1024 * 1024)
self.assertEqual(human_readable_to_byte("0.5Gb"), 0.5 * 1024 * 1024 * 1024)
self.assertEqual(human_readable_to_byte("0.5gb"), 0.5 * 1024 * 1024 * 1024)
assert human_readable_to_byte("0.5GB") == 0.5 * 1024 * 1024 * 1024
assert human_readable_to_byte("0.5gB") == 0.5 * 1024 * 1024 * 1024
assert human_readable_to_byte("0.5Gb") == 0.5 * 1024 * 1024 * 1024
assert human_readable_to_byte("0.5gb") == 0.5 * 1024 * 1024 * 1024

View file

@ -73,8 +73,8 @@ class TestLargeFileS3(unittest.TestCase):
Bucket=credentials["large_files_bucket_name"], Prefix="test-file"
)
self.assertEqual(lf._version, 2)
self.assertEqual(lf._local_name, "test-file-2")
assert lf._version == 2
assert lf._local_name == "test-file-2"
@patch.object(boto3, "client")
def test_initialized_with_file(self, client: Any) -> None:
@ -116,5 +116,5 @@ class TestLargeFileS3(unittest.TestCase):
Bucket=credentials["large_files_bucket_name"], Prefix="test-file"
)
self.assertEqual(lf._version, 2)
self.assertEqual(lf._local_name, "test-file-2")
assert lf._version == 2
assert lf._local_name == "test-file-2"

View file

@ -9,18 +9,18 @@ class TestClean(unittest.TestCase):
clean_xml = "Hi, my name is András! <3 <> <|"
clean_xml_ascii = "Hi, my name is Andras! <3 <> <|"
self.assertEqual(clean(xml), clean_xml)
self.assertEqual(clean(xml, ignore_xml=True, ignore_latex=True), xml)
self.assertEqual(clean(xml, convert_to_ascii=True), clean_xml_ascii)
assert clean(xml) == clean_xml
assert clean(xml, ignore_xml=True, ignore_latex=True) == xml
assert clean(xml, convert_to_ascii=True) == clean_xml_ascii
def test_simple_latex_handling(self) -> None:
latex = 'Bj\\"{o}rn is \\textit{happy} 🙂'
clean_latex = "Björn is happy 🙂"
clean_latex_ascii = "Bjorn is happy"
self.assertEqual(clean(latex), clean_latex)
self.assertEqual(clean(latex, ignore_latex=True), latex)
self.assertEqual(clean(latex, convert_to_ascii=True), clean_latex_ascii)
assert clean(latex) == clean_latex
assert clean(latex, ignore_latex=True) == latex
assert clean(latex, convert_to_ascii=True) == clean_latex_ascii
def test_cursed(self) -> None:
cursed = """
@ -28,8 +28,8 @@ class TestClean(unittest.TestCase):
"""
cleaned = "to the moon"
self.assertEqual(clean(cursed), cursed.strip())
self.assertEqual(clean(cursed, convert_to_ascii=True), cleaned)
assert clean(cursed) == cursed.strip()
assert clean(cursed, convert_to_ascii=True) == cleaned
def test_whitespace(self) -> None:
text = """
@ -43,9 +43,9 @@ class TestClean(unittest.TestCase):
""" # noqa: W293
cleaned = "word1 word2 wo rd3"
self.assertEqual(clean(text, convert_to_ascii=True), cleaned)
self.assertEqual(clean(text, ignore_xml=True, ignore_latex=True), cleaned)
self.assertEqual(clean(text), cleaned)
assert clean(text, convert_to_ascii=True) == cleaned
assert clean(text, ignore_xml=True, ignore_latex=True) == cleaned
assert clean(text) == cleaned
def test_hyphens(self) -> None:
text = """
@ -57,20 +57,20 @@ class TestClean(unittest.TestCase):
"""
cleaned = "break - word break-word break-word break-word break-word"
self.assertEqual(clean(text), cleaned)
assert clean(text) == cleaned
def test_T_I_T_L_E_case(self) -> None:
text = "an a r t i c l e is to F I N D the purpose of a tree"
cleaned = "an article is to FIND the purpose of a tree"
self.assertEqual(clean(text), cleaned)
assert clean(text) == cleaned
def test_bracket_removal(self) -> None:
text = "something [0], and [frefe, ferf]"
cleaned = "something, and"
self.assertEqual(clean(text, remove_brackets=True), cleaned)
assert clean(text, remove_brackets=True) == cleaned
self.assertEqual(
clean(text, ignore_xml=True, ignore_latex=True, remove_brackets=True),
cleaned,
@ -78,7 +78,7 @@ class TestClean(unittest.TestCase):
self.assertEqual(
clean(text, convert_to_ascii=True, remove_brackets=True), cleaned
)
self.assertEqual(clean(text), text)
assert clean(text) == text
def test_latex_math_handling(self) -> None:
latex = "An increase of 3% was achieved with $q_1 = \\frac{3}{5}$."
@ -86,10 +86,10 @@ class TestClean(unittest.TestCase):
clean_latex = "An increase of 3% was achieved with q_1 = 3/5."
clean_bad_latex = "An increase of 3% was achieved with q_1 = 3//5."
self.assertEqual(clean(latex), clean_latex)
self.assertEqual(clean(bad_latex), clean_bad_latex)
self.assertEqual(clean(latex, ignore_latex=True), latex)
self.assertEqual(clean(bad_latex, ignore_latex=True), bad_latex)
assert clean(latex) == clean_latex
assert clean(bad_latex) == clean_bad_latex
assert clean(latex, ignore_latex=True) == latex
assert clean(bad_latex, ignore_latex=True) == bad_latex
def test_everything(self) -> None:
text = """
@ -102,9 +102,9 @@ class TestClean(unittest.TestCase):
)
def test_empty(self) -> None:
self.assertEqual(clean("", convert_to_ascii=True), "")
assert clean("", convert_to_ascii=True) == ""
def test_punctuation_fixing(self) -> None:
text = " Dear reader ( or listener ) , welcome ! "
fixed = "Dear reader (or listener), welcome!"
self.assertEqual(clean(text), fixed)
assert clean(text) == fixed

View file

@ -8,9 +8,9 @@ class TestGetSentences(unittest.TestCase):
text = "This is a complete sentence. So is this. However this is n" # ot.
expected = ["This is a complete sentence.", "So is this.", "However this is n"]
self.assertEqual(get_sentences(text), expected)
self.assertEqual(get_sentences(text, ignore_partial=True), expected[0:2])
assert get_sentences(text) == expected
assert get_sentences(text, ignore_partial=True) == expected[0:2]
def test_empty(self) -> None:
self.assertEqual(get_sentences(""), [])
self.assertEqual(get_sentences("", ignore_partial=True), [])
assert get_sentences("") == []
assert get_sentences("", ignore_partial=True) == []

View file

@ -9,11 +9,11 @@ from src.great_ai.utilities.language import (
class TestLanguage(unittest.TestCase):
def test_predict_language(self) -> None:
self.assertEqual(predict_language("This is an English text."), "en")
self.assertEqual(predict_language("Ez egy magyar szöveg."), "hu")
self.assertEqual(predict_language("此處按原典,應為「黃武元年」,而電子稿此處為「黃初元年」。"), "zh-TW")
self.assertEqual(predict_language("32"), "und")
self.assertEqual(predict_language(""), "und")
assert predict_language("This is an English text.") == "en"
assert predict_language("Ez egy magyar szöveg.") == "hu"
assert predict_language("此處按原典,應為「黃武元年」,而電子稿此處為「黃初元年」。") == "zh-TW"
assert predict_language("32") == "und"
assert predict_language("") == "und"
def test_is_english(self) -> None:
self.assertTrue(is_english("en"))
@ -27,10 +27,10 @@ class TestLanguage(unittest.TestCase):
self.assertFalse(is_english(None))
def english_name_of_language(self) -> None:
self.assertEqual(english_name_of_language("en"), "English")
self.assertEqual(english_name_of_language("hu"), "Hungarian")
self.assertEqual(english_name_of_language("zh"), "Chinese")
self.assertEqual(english_name_of_language("zh-TW"), "Chinese")
self.assertEqual(english_name_of_language("und"), "Unknown language")
self.assertEqual(english_name_of_language(""), "Unknown language")
self.assertEqual(english_name_of_language(None), "Unknown language")
assert english_name_of_language("en") == "English"
assert english_name_of_language("hu") == "Hungarian"
assert english_name_of_language("zh") == "Chinese"
assert english_name_of_language("zh-TW") == "Chinese"
assert english_name_of_language("und") == "Unknown language"
assert english_name_of_language("") == "Unknown language"
assert english_name_of_language(None) == "Unknown language"

View file

@ -127,13 +127,13 @@ class TestLemmatizeText(unittest.TestCase):
"._PUNCT",
]
self.assertEqual(lemmatize_text(text), lemmatized)
self.assertEqual(lemmatize_text(text, add_part_of_speech=True), lemmatized_pos)
self.assertEqual(lemmatize_text(text, add_negation=True), lemmatized_neg)
assert lemmatize_text(text) == lemmatized
assert lemmatize_text(text, add_part_of_speech=True) == lemmatized_pos
assert lemmatize_text(text, add_negation=True) == lemmatized_neg
self.assertEqual(
lemmatize_text(text, add_negation=True, add_part_of_speech=True),
lemmatized_pos_neg,
)
def test_empty(self) -> None:
self.assertEqual(lemmatize_text(""), [])
assert lemmatize_text("") == []

View file

@ -8,13 +8,13 @@ class TestLemmatizeToken(unittest.TestCase):
def test_simple(self) -> None:
token = nlp("Center")[0]
self.assertEqual(lemmatize_token(token), "centre")
self.assertEqual(lemmatize_token(token, add_negation=True), "centre")
self.assertEqual(lemmatize_token(token, add_part_of_speech=True), "centre_NOUN")
assert lemmatize_token(token) == "centre"
assert lemmatize_token(token, add_negation=True) == "centre"
assert lemmatize_token(token, add_part_of_speech=True) == "centre_NOUN"
def test_punctuation(self) -> None:
token = nlp("This.")[1]
self.assertEqual(lemmatize_token(token), ".")
self.assertEqual(lemmatize_token(token, add_negation=True), ".")
self.assertEqual(lemmatize_token(token, add_part_of_speech=True), "._PUNCT")
assert lemmatize_token(token) == "."
assert lemmatize_token(token, add_negation=True) == "."
assert lemmatize_token(token, add_part_of_speech=True) == "._PUNCT"

View file

@ -10,7 +10,7 @@ class TestParallelMap(unittest.TestCase):
inputs = range(COUNT)
expected = [v**2 for v in range(COUNT)]
self.assertEqual(parallel_map(lambda v: v**2, inputs), expected)
assert parallel_map(lambda v: v**2, inputs) == expected
def test_simple_case_without_progress_bar(self) -> None:
inputs = range(COUNT)
@ -31,7 +31,7 @@ class TestParallelMap(unittest.TestCase):
)
def test_no_op(self) -> None:
self.assertEqual(parallel_map(lambda v: v**2, [], disable_progress=True), [])
assert parallel_map(lambda v: v**2, [], disable_progress=True) == []
self.assertEqual(
parallel_map(lambda v: v**2, [], disable_progress=True, chunk_size=100),
[],

View file

@ -28,22 +28,22 @@ class TestPublicationTEI(unittest.TestCase):
cls.test_xml = f.read()
def test_metadata_extraction(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).publication_metadata, metadata)
assert PublicationTEI(self.test_xml).publication_metadata == metadata
def test_authors(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).authors, authors)
assert PublicationTEI(self.test_xml).authors == authors
def test_content(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).content, content)
assert PublicationTEI(self.test_xml).content == content
def test_sentences(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).sentences, sentences)
assert PublicationTEI(self.test_xml).sentences == sentences
def test_bookmarks(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).bookmarks, bookmarks)
assert PublicationTEI(self.test_xml).bookmarks == bookmarks
def test_abstract(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).abstract_sentences, abstract)
assert PublicationTEI(self.test_xml).abstract_sentences == abstract
def test_introduction(self) -> None:
self.assertEqual(
@ -51,7 +51,7 @@ class TestPublicationTEI(unittest.TestCase):
)
def test_conclusion(self) -> None:
self.assertEqual(PublicationTEI(self.test_xml).conclusion_sentences, conclusion)
assert PublicationTEI(self.test_xml).conclusion_sentences == conclusion
def test_empty1(self) -> None:
tei = PublicationTEI("<TEI/>")

View file

@ -26,8 +26,8 @@ class TestUnique(unittest.TestCase):
expected = original
self.assertEqual(unique(values), expected)
self.assertEqual(unique(values, key=lambda v: v), expected)
assert unique(values) == expected
assert unique(values, key=lambda v: v) == expected
def test_with_key_0(self) -> None:
values = original
@ -39,7 +39,7 @@ class TestUnique(unittest.TestCase):
("d", 2),
]
self.assertEqual(unique(values, key=lambda v: v[0]), expected)
assert unique(values, key=lambda v: v[0]) == expected
def test_with_key_1(self) -> None:
values = original
@ -51,4 +51,4 @@ class TestUnique(unittest.TestCase):
("d", 2),
]
self.assertEqual(unique(values, key=lambda v: v[1]), expected)
assert unique(values, key=lambda v: v[1]) == expected