From 37ab0589df3b8047a2aad45db880456d42b710c6 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 11 Dec 2023 11:44:20 +0200 Subject: [PATCH] Fix regex to validate a referance. --- setup.py | 2 +- src/getbible/getbible_reference.py | 2 +- tests/test_getbible_book_number.py | 12 +++++++++++- tests/test_getbible_reference.py | 28 +++++++++++++++++++--------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 42360f6..1eb0fa5 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="getbible", - version="1.1.0", + version="1.1.1", author="Llewellyn van der Merwe", author_email="getbible@vdm.io", description="A Python package to retrieving Bible references with ease.", diff --git a/src/getbible/getbible_reference.py b/src/getbible/getbible_reference.py index 15929fd..9cc64c5 100644 --- a/src/getbible/getbible_reference.py +++ b/src/getbible/getbible_reference.py @@ -15,7 +15,7 @@ class BookReference: class GetBibleReference: def __init__(self): self.__get_book = GetBibleBookNumber() - self.__pattern = re.compile(r'^[\w\s,:-]{1,50}$', re.UNICODE) + self.__pattern = re.compile(r'[\w\s,:-]{1,50}', re.UNICODE) self.__cache = {} self.__cache_limit = 5000 diff --git a/tests/test_getbible_book_number.py b/tests/test_getbible_book_number.py index 03a7043..a72a15d 100644 --- a/tests/test_getbible_book_number.py +++ b/tests/test_getbible_book_number.py @@ -37,6 +37,16 @@ def test_valid_1_john(self): actual_result = self.get_book.number('1 John', 'kjv') self.assertEqual(actual_result, expected_result, "Failed to find '1 John' in 'kjv' translation") + def test_valid_genesis(self): + expected_result = 1 + actual_result = self.get_book.number('בְּרֵאשִׁית', 'codex') + self.assertEqual(actual_result, expected_result, "Failed to find 'בְּרֵאשִׁית' in 'codex' translation") + + def test_valid_1_samuel(self): + expected_result = 9 + actual_result = self.get_book.number("שמא",'aleppo') + self.assertEqual(actual_result, expected_result, "Failed to find 'שמא' in 'aleppo' translation") + def test_valid_1_peter_ch(self): expected_result = 60 actual_result = self.get_book.number('彼得前书', 'cns') @@ -47,7 +57,7 @@ def test_valid_first_john(self): actual_result = self.get_book.number('First John', 'kjv') self.assertEqual(actual_result, expected_result, "Failed to find 'First John' in 'kjv' translation") - def test_valid_1_john(self): + def test_valid_one_john(self): expected_result = 62 actual_result = self.get_book.number('62', 'kjv') self.assertEqual(actual_result, expected_result, "Failed to find '62' in 'kjv' translation") diff --git a/tests/test_getbible_reference.py b/tests/test_getbible_reference.py index dba5e5d..a9a58bd 100644 --- a/tests/test_getbible_reference.py +++ b/tests/test_getbible_reference.py @@ -8,25 +8,35 @@ def setUp(self): self.get = GetBibleReference() def test_valid_reference(self): - expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='Gen 1:2-7') actual_result = self.get.ref('Gen 1:2-7', 'kjv') + expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='Gen 1:2-7') self.assertEqual(actual_result, expected_result, "Failed to find 'Gen 1:2-7' book reference.") + def test_valid_genesis_hebrew(self): + actual_result = self.get.ref('בְּרֵאשִׁית 1:23-30', 'codex') + expected_result = BookReference(book=1, chapter=1, verses=[23, 24, 25, 26, 27, 28, 29, 30], reference='בְּרֵאשִׁית 1:23-30') + self.assertEqual(actual_result, expected_result, "Failed to find 'בְּרֵאשִׁית 1:23-30' in 'codex' translation") + def test_valid_reference_ch(self): - expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='创世记1:2-7') actual_result = self.get.ref('创世记1:2-7', 'cns') + expected_result = BookReference(book=1, chapter=1, verses=[2, 3, 4, 5, 6, 7], reference='创世记1:2-7') self.assertEqual(actual_result, expected_result, "Failed to find '创世记1:2-7' book reference") def test_valid_reference_missing_verse_ch(self): - expected_result = BookReference(book=1, chapter=1, verses=[2], reference='创记 1:2-') actual_result = self.get.ref('创记 1:2-', 'cus') + expected_result = BookReference(book=1, chapter=1, verses=[2], reference='创记 1:2-') self.assertEqual(actual_result, expected_result, "Failed to find '创记 1:2-' book reference") def test_valid_reference_missing_verse__ch(self): - expected_result = BookReference(book=1, chapter=1, verses=[5], reference='创记 1:-5') actual_result = self.get.ref('创记 1:-5', 'cus') + expected_result = BookReference(book=1, chapter=1, verses=[5], reference='创记 1:-5') self.assertEqual(actual_result, expected_result, "Failed to find '创记 1:-5' book reference") + def test_valid_revelation_arabic(self): + actual_result = self.get.ref('رؤ 22:19') + expected_result = BookReference(book=66, chapter=22, verses=[19], reference='رؤ 22:19') + self.assertEqual(actual_result, expected_result, "Failed to find 'رؤ 22:19' in 'arabicsv' translation") + def test_valid_reference_ch_no_trans(self): actual_result = self.get.ref('创世记') expected_result = BookReference(book=1, chapter=1, verses=[1], reference='创世记') @@ -38,8 +48,8 @@ def test_valid_reference_ch_no__trans(self): self.assertEqual(actual_result, expected_result, "Failed to find '创记 1:1' book reference") def test_valid_1_john(self): - expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1 John') actual_result = self.get.ref('1 John', 'kjv') + expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1 John') self.assertEqual(actual_result, expected_result, "Failed to find '1 John 1:1' book reference") def test_valid_1_peter_ch(self): @@ -48,18 +58,18 @@ def test_valid_1_peter_ch(self): self.assertEqual(actual_result, expected_result, "Failed to find '彼得前书 1:1' book reference") def test_valid_first_john(self): - expected_result = BookReference(book=62, chapter=3, verses=[16, 19, 20, 21], reference='First John 3:16,19-21') actual_result = self.get.ref('First John 3:16,19-21', 'kjv') + expected_result = BookReference(book=62, chapter=3, verses=[16, 19, 20, 21], reference='First John 3:16,19-21') self.assertEqual(actual_result, expected_result, "Failed to find 'First John 1:2-7' book reference.") def test_valid_mismatch_nospace_call(self): - expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1Jn') actual_result = self.get.ref('1Jn', 'aov') + expected_result = BookReference(book=62, chapter=1, verses=[1], reference='1Jn') self.assertEqual(actual_result, expected_result, "Failed to find '1Jn 1:1' book reference.") def test_valid_mismatch_call(self): - expected_result = BookReference(book=62, chapter=5, verses=[1], reference='1 John 5') actual_result = self.get.ref('1 John 5', 'aov') + expected_result = BookReference(book=62, chapter=5, verses=[1], reference='1 John 5') self.assertEqual(actual_result, expected_result, "Failed to find '1 John 5:1' book reference.") def test_invalid_reference(self): @@ -69,8 +79,8 @@ def test_invalid_reference(self): self.assertEqual(str(actual.exception), expected_exception) def test_nonexistent_translation(self): - expected_result = BookReference(book=1, chapter=1, verses=[1], reference='Gen') actual_result = self.get.ref('Gen', 'nonexistent') + expected_result = BookReference(book=1, chapter=1, verses=[1], reference='Gen') self.assertEqual(actual_result, expected_result, "Failed to find 'Gen 1:1' book reference.")