Skip to content

Commit

Permalink
improv: remove enum and rollback codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Qbecb1zen committed Jan 7, 2022
1 parent 44f3da3 commit 8d920e0
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from utils import FakeLanguages
from librelingo_utils import clean_word


Expand All @@ -7,11 +6,11 @@ def test_empty_string():


def test_removes_parentheses():
assert clean_word("(foo") == FakeLanguages.LANG_1
assert clean_word("(foo") == "foo"


def test_removes_comma():
assert clean_word("foo,") == FakeLanguages.LANG_1
assert clean_word("foo,") == "foo"


def test_doesnt_remove_parts_of_word_1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from librelingo_fakes import fakes
from librelingo_utils import calculate_number_of_levels
from utils import FakeLanguages
from librelingo_json_export.course import _get_course_data

course_with_markdown = fakes.customize(
Expand Down Expand Up @@ -30,7 +29,7 @@ def test__get_course_data_return_value():
"specialCharacters": ["ä", "ß"],
"license": {
"name": {
"short": FakeLanguages.LANG_1,
"short": "foo",
"full": "foo bar license",
},
"link": None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from librelingo_fakes import fakes
from librelingo_json_export.dictionary import _define_words_in_sentence
from utils import FakeLanguages


def test_empty_sentence():
Expand All @@ -16,21 +15,21 @@ def mock_define_word(mocker):
def test_calls_define_word_with_the_correct_data(mock_define_word):
_define_words_in_sentence(fakes.course1, "foo bar baz", False)
assert mock_define_word.call_count == 3
mock_define_word.assert_any_call(fakes.course1, FakeLanguages.LANG_1, False)
mock_define_word.assert_any_call(fakes.course1, FakeLanguages.LANG_2, False)
mock_define_word.assert_any_call(fakes.course1, "foo", False)
mock_define_word.assert_any_call(fakes.course1, "bar", False)
mock_define_word.assert_any_call(fakes.course1, "baz", False)


def test_calls_define_word_with_the_correct_word_that_has_space(mock_define_word):
_define_words_in_sentence(fakes.course1, "foo {bar baz}", False)
assert mock_define_word.call_count == 2
mock_define_word.assert_any_call(fakes.course1, FakeLanguages.LANG_1, False)
mock_define_word.assert_any_call(fakes.course1, "foo", False)
mock_define_word.assert_any_call(fakes.course1, "bar baz", False)


def test_returns_correct_value(mock_define_word):
mock_define_word.return_value = fakes.fake_value()
assert _define_words_in_sentence(fakes.course1, FakeLanguages.LANG_1, True) == [
assert _define_words_in_sentence(fakes.course1, "foo", True) == [
mock_define_word.return_value
]

Expand Down
25 changes: 10 additions & 15 deletions apps/librelingo_json_export/tests/test_utils_get_dumb_opaque_id.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
from librelingo_fakes import fakes
from librelingo_utils import get_dumb_opaque_id
from utils import FakeLanguages


def test_word_only_first_meaning_matters_1():
fake_name = str(fakes.fake_value())
phrase_1 = fakes.customize(fakes.word1, in_source_language=[FakeLanguages.LANG_1])
phrase_2 = fakes.customize(
fakes.word1, in_source_language=[FakeLanguages.LANG_1, FakeLanguages.LANG_2]
)
phrase_1 = fakes.customize(fakes.word1, in_source_language=["foo"])
phrase_2 = fakes.customize(fakes.word1, in_source_language=["foo", "bar"])
assert get_dumb_opaque_id(fake_name, phrase_1) == get_dumb_opaque_id(
fake_name, phrase_2
)


def test_phrase_only_first_meaning_matters_1():
fake_name = str(fakes.fake_value())
phrase_1 = fakes.customize(fakes.phrase1, in_source_language=[FakeLanguages.LANG_1])
phrase_1 = fakes.customize(fakes.phrase1, in_source_language=["foo"])
phrase_2 = fakes.customize(
fakes.phrase1,
in_source_language=[FakeLanguages.LANG_1, FakeLanguages.LANG_2],
in_source_language=["foo", "bar"],
)
assert get_dumb_opaque_id(fake_name, phrase_1) == get_dumb_opaque_id(
fake_name, phrase_2
Expand All @@ -28,21 +25,19 @@ def test_phrase_only_first_meaning_matters_1():

def test_word_only_first_meaning_matters_2():
fake_name = str(fakes.fake_value())
phrase_1 = fakes.customize(fakes.word1, in_target_language=[FakeLanguages.LANG_1])
phrase_2 = fakes.customize(
fakes.word1, in_target_language=[FakeLanguages.LANG_1, FakeLanguages.LANG_2]
)
phrase_1 = fakes.customize(fakes.word1, in_target_language=["foo"])
phrase_2 = fakes.customize(fakes.word1, in_target_language=["foo", "bar"])
assert get_dumb_opaque_id(fake_name, phrase_1) == get_dumb_opaque_id(
fake_name, phrase_2
)


def test_phrase_only_first_meaning_matters_2():
fake_name = str(fakes.fake_value())
phrase_1 = fakes.customize(fakes.phrase1, in_target_language=[FakeLanguages.LANG_1])
phrase_1 = fakes.customize(fakes.phrase1, in_target_language=["foo"])
phrase_2 = fakes.customize(
fakes.phrase1,
in_target_language=[FakeLanguages.LANG_1, FakeLanguages.LANG_2],
in_target_language=["foo", "bar"],
)
assert get_dumb_opaque_id(fake_name, phrase_1) == get_dumb_opaque_id(
fake_name, phrase_2
Expand All @@ -51,8 +46,8 @@ def test_phrase_only_first_meaning_matters_2():

def test_the_first_meaning_does_matter():
fake_name = str(fakes.fake_value())
phrase_1 = fakes.customize(fakes.phrase1, in_target_language=[FakeLanguages.LANG_1])
phrase_2 = fakes.customize(fakes.phrase1, in_target_language=[FakeLanguages.LANG_2])
phrase_1 = fakes.customize(fakes.phrase1, in_target_language=["foo"])
phrase_2 = fakes.customize(fakes.phrase1, in_target_language=["bar"])
assert get_dumb_opaque_id(fake_name, phrase_1) != get_dumb_opaque_id(
fake_name, phrase_2
)
6 changes: 0 additions & 6 deletions apps/librelingo_json_export/tests/utils.py

This file was deleted.

104 changes: 104 additions & 0 deletions apps/librelingo_yaml_loader/tests/test_yaml_load_dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import pytest
from librelingo_types import (
Module,
Skill,
Word,
DictionaryItem,
)
from librelingo_yaml_loader.yaml_loader import (
_load_dictionary,
)


def test_load_dictionary_returns_a_list(module_with_word):
assert isinstance(_load_dictionary([module_with_word[0]]), list)


def test_load_dictionary_returns_a_list_of_dictionary_items(module_with_word):
assert isinstance(_load_dictionary([module_with_word[0]])[0], DictionaryItem)


def test_load_dictionary_includes_word_from_new_word(module_with_word):
_, in_source_language, in_target_language = module_with_word
dict_item = DictionaryItem(
word=in_source_language[0],
definition=in_target_language[0],
is_in_target_language=False,
)
assert dict_item in _load_dictionary([module_with_word[0]])


def test_load_dictionary_includes_reverse_word_from_new_word(module_with_word):
_, in_source_language, in_target_language = module_with_word
dict_item = DictionaryItem(
word=in_target_language[0],
definition=in_source_language[0],
is_in_target_language=True,
)
assert dict_item in _load_dictionary([module_with_word[0]])


def test_load_dictionary_includes_word_from_mini_dictionary(module_with_word):
module, _, __ = module_with_word
module.skills[0] = Skill(
**{**module.skills[0]._asdict(), "dictionary": [("foo", ("bar", "baz"), False)]}
)
assert DictionaryItem("foo", "bar\nbaz", False) in _load_dictionary(
[module_with_word[0]]
)


def test_load_dictionary_handles_multiple_word_per_skill(module_with_word):
module_with_word[0].skills[0].words.append(get_fake_word()[0])
assert len(_load_dictionary([module_with_word[0]])) == 4


def test_load_dictionary_handles_multiple_skills_per_module(module_with_word):
module_with_word[0].skills.append(
Skill("", "", "", [get_fake_word()[0]], [], [], None, None)
)
assert len(_load_dictionary([module_with_word[0]])) == 4


def test_load_dictionary_handles_multiple_modules(module_with_word):
new_module = Module(
"", "", [Skill("", "", "", [get_fake_word()[0]], [], [], None, None)]
)
assert len(_load_dictionary([module_with_word[0], new_module])) == 4


def test_load_dictionary_includes_duplicate_words_only_once(module_with_word):
new_module = Module(
"",
"",
[
Skill(
"", "", "", [module_with_word[0].skills[0].words[0]], [], [], None, None
)
],
)
assert len(_load_dictionary([module_with_word[0], new_module])) == 2


def test_load_dictionary_has_a_single_string_definition(module_with_word):
assert isinstance(_load_dictionary([module_with_word[0]])[0].definition, str)


def test_load_dictionary_includes_duplicate_words_includes_multiple_definitions(
module_with_word,
):
random_new_word = get_fake_word()[0]
existing_word = module_with_word[0].skills[0].words[0]
duplicate_word = Word(
in_source_language=existing_word.in_source_language,
in_target_language=random_new_word.in_target_language,
pictures=[],
)
new_module = Module(
"", "", [Skill("", "", "", [duplicate_word], [], [], None, None)]
)
definition = _load_dictionary([module_with_word[0], new_module])[0].definition
assert (
random_new_word.in_target_language[0] in definition
and existing_word.in_target_language[0] in definition
)

0 comments on commit 8d920e0

Please sign in to comment.