Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): move load_dictionary tests into a separated file #2005

Merged
merged 39 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
880d800
chore(deps): update dependency svelte to v3.46.1
renovate-bot Jan 12, 2022
81f0f87
chore(deps): bump follow-redirects from 1.13.2 to 1.14.7 (#1994)
dependabot[bot] Jan 13, 2022
626036b
chore(deps): update dependency svelte-check to v2.3.0
renovate-bot Jan 13, 2022
1476d04
chore(deps): update dependency prettier-plugin-svelte to v2.6.0 (#1996)
renovate[bot] Jan 13, 2022
be01fa7
chore(deps): update dependency eslint-plugin-svelte3 to v3.4.0 (#1995)
renovate[bot] Jan 13, 2022
0a4b244
chore(deps): update dependency @percy/cli to v1.0.0-beta.73
renovate-bot Jan 13, 2022
291dde0
chore(deps): update dependency sass-loader to v10.2.1
renovate-bot Jan 14, 2022
27723a3
chore(deps): update dependency svelte to v3.46.2
renovate-bot Jan 15, 2022
d64da8b
feat(devtools): move the 4 local courses to the configuration file, s…
szabgab Jan 15, 2022
7f50dff
feat(devtools): make program executable
szabgab Jan 15, 2022
2e65148
fix(courses): fic repository url of courses
szabgab Jan 15, 2022
fe5cdcd
fix(devtools): add trailing slash to url
szabgab Jan 15, 2022
effc465
fix(devtools): fix the url where we link to
szabgab Jan 15, 2022
75d9424
fix(devtool): link to basque course fixed
szabgab Jan 15, 2022
9a5ef32
ref(devtools): eliminate the need for the duplicate course_dir parameter
szabgab Jan 15, 2022
d5a65b9
feat(devtools): show all counters on the front pages
szabgab Jan 15, 2022
a6dc4d6
feat(devtools): collect history
szabgab Jan 15, 2022
ab2c8bb
feat(devtools): split up courses.html in preparation for the history.…
szabgab Jan 15, 2022
a6955bf
feat(devtools): separate get_template in preparation for multiple tem…
szabgab Jan 15, 2022
9210dab
feat(devtools): add experimantal history page
szabgab Jan 15, 2022
0b0a63a
chore(deps): update dependency eslint-plugin-jest to v25.7.0
renovate-bot Jan 15, 2022
73e32cd
chore(deps): update dependency eslint to v8.7.0
renovate-bot Jan 16, 2022
bb74688
refactor(tests): various test refactors
vil02 Jan 16, 2022
1e8a99e
Merge branch 'main' of github.com:kantord/LibreLingo
kantord Jan 16, 2022
a7614ee
chore: remove import error
dushyantbhardwaj9 Jan 16, 2022
6f6ebfb
refactor(codebase): type all possible instances (#1964)
qbecb1zen Jan 16, 2022
55d965e
refactor(tests): add test_export_course_skills.py (#1992)
vil02 Jan 16, 2022
67b7ab1
fix: avoid potential bugs (#1999)
vil02 Jan 16, 2022
a0f8fa8
chore: update python dependencies (#1991)
kantord Jan 16, 2022
7b04524
improv: move load_dictionary tests into a separated file
Jan 16, 2022
c0e9171
style: fix lint and formatting
Jan 16, 2022
ac710bd
chore: add robots.txt (#2004)
kantord Jan 16, 2022
70e7aba
feat(devtools): add link to the new legacy devtool
szabgab Jan 17, 2022
ae540f7
refactor(tests): fix failing tests
Jan 17, 2022
43c1bb3
Merge branch 'main' into qbecb1zen/refactor-load-dictionary-test
Jan 17, 2022
77c0005
Merge remote-tracking branch 'upstream/main'
Feb 2, 2022
3c49b3e
Merge branch 'main' into qbecb1zen/refactor-load-dictionary-test
Feb 2, 2022
503c546
style: fix formatting
Feb 3, 2022
4931e94
improv: resolve merge errors
Feb 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 0 additions & 116 deletions apps/librelingo_yaml_loader/tests/test_yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
_load_modules,
_load_skills,
_load_skill,
_load_dictionary,
)
from librelingo_fakes import fakes

Expand Down Expand Up @@ -708,121 +707,6 @@ def test_calls_convert_phrases_with_correct_values(self):
self.convert_phrases.assert_called_with(self.fake_values["fake_phrases"])


def get_fake_word_values():
in_target_language = [str(fakes.number())]
in_source_language = [str(fakes.number())]

return in_source_language, in_target_language


def get_fake_word():
in_source_language, in_target_language = get_fake_word_values()
word = Word(in_target_language, in_source_language, [])
return word, in_source_language, in_target_language


@pytest.fixture
def module_with_word():
word, in_source_language, in_target_language = get_fake_word()
my_module = Module("", "", skills=[Skill("", "", "", [word], [], [], None, None)])

return my_module, in_source_language, in_target_language


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
)


@patch("librelingo_yaml_loader.yaml_loader._load_yaml")
def test_load_module_complains_about_an_empty_file(load_yaml):
random_path = fakes.path()
Expand Down
115 changes: 115 additions & 0 deletions apps/librelingo_yaml_loader/tests/test_yaml_loader_load_dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import pytest

from librelingo_types import (
Module,
Skill,
Word,
DictionaryItem,
)
from librelingo_yaml_loader.yaml_loader import (
_load_dictionary,
)

from .utils import get_fake_word


@pytest.fixture
def module_with_word():
word, in_source_language, in_target_language = get_fake_word()
my_module = Module("", "", skills=[Skill("", "", "", [word], [], [], None, None)])

return my_module, in_source_language, in_target_language


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
)
15 changes: 15 additions & 0 deletions apps/librelingo_yaml_loader/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from librelingo_fakes import fakes
from librelingo_types import Word


def _get_fake_word_values():
in_target_language = [str(fakes.number())]
in_source_language = [str(fakes.number())]

return in_source_language, in_target_language


def get_fake_word():
in_source_language, in_target_language = _get_fake_word_values()
word = Word(in_target_language, in_source_language, [])
return word, in_source_language, in_target_language