Skip to content

Commit

Permalink
Glossary: directRead method: add sqlite=False argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 19, 2024
1 parent 1f3153d commit fd3b29c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pyglossary/glossary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,14 @@ def _openReader(self, reader: Any, filename: str) -> None: # noqa: ANN401
def directRead(
self,
filename: str,
sqlite=False,
**options, # noqa: ANN003
) -> bool:
self._setTmpDataDir(filename)
if sqlite:
self._switchToSQLite(
inputFilename=filename,
)
return self._read(
filename=filename,
direct=True,
Expand Down
20 changes: 16 additions & 4 deletions tests/glossary_v2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,26 @@ def test_config_attr_set(self):
def test_directRead_txt_1(self):
inputFilename = self.downloadFile("100-en-fa.txt")
glos = self.glos = Glossary()
res = glos.directRead(filename=inputFilename)
self.assertTrue(res)
self.assertTrue(glos.directRead(filename=inputFilename))
self.assertEqual(glos.sourceLangName, "English")
self.assertEqual(glos.targetLangName, "Persian")
self.assertIn("Sample: ", glos.getInfo("name"))

entryCount = sum(1 for _ in glos)
self.assertEqual(entryCount, 100)
words = [entry.l_word for entry in glos]
self.assertEqual(len(words), 100)

glos.cleanup()
del glos
glos2 = self.glos = Glossary()

self.assertTrue(glos2.directRead(filename=inputFilename, sqlite=True))
self.assertEqual(glos2.sourceLangName, "English")
self.assertEqual(glos2.targetLangName, "Persian")
self.assertIn("Sample: ", glos2.getInfo("name"))

words2 = [entry.l_word for entry in glos2]

self.assertEqual(words, words2)

def test_lang_1(self):
glos = self.glos = Glossary()
Expand Down

0 comments on commit fd3b29c

Please sign in to comment.