Skip to content

Commit

Permalink
Make case insensitive (#39)
Browse files Browse the repository at this point in the history
* add test for case insensitivity
* fix up tree_allows_any_case test
* fix case sensitivity issues
  • Loading branch information
alxwrd authored and jmsv committed Jun 20, 2018
1 parent fadbc09 commit 9c8127f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ety/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(self, word, language='eng', is_source=False):
'direct': [],
'recursive': []
}
self._id = u"{}:{}".format(self.word, self.language.iso)
self._id = u"{}:{}".format(
self.word.lower(), self.language.iso.lower())

def origins(self, recursive=False):
search = 'recursive' if recursive else 'direct'
Expand All @@ -32,8 +33,10 @@ def origins(self, recursive=False):
return o

row = list(filter(
lambda entry: entry['a_word'] == self.word and entry[
'a_lang'] == self.language.iso, etymwn_data))
lambda entry: (
entry['a_word'].lower() == self.word.lower()
and entry['a_lang'].lower() == self.language.iso.lower()),
etymwn_data))

o = [Word(item['b_word'], item['b_lang']) for item in row]

Expand Down
12 changes: 12 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ def test_census_origins(self):

self.assertEqual(d.origins(recursive=True), e + f)

def test_origins_allows_any_case(self):
wonky_word_origins = ety.origins("tEsT")
lower_word_origins = ety.origins("test")

self.assertEqual(wonky_word_origins, lower_word_origins)

def test_tree_allows_any_case(self):
wonky_word_tree = [node.data for node in ety.tree("tEsT").all_nodes()]
lower_word_tree = [node.data for node in ety.tree("test").all_nodes()]

self.assertEqual(wonky_word_tree, lower_word_tree)

@stdout_capture
def test_cli_no_args(self, output):
words = ["test"]
Expand Down

0 comments on commit 9c8127f

Please sign in to comment.