Skip to content

Commit 7dd5409

Browse files
committed
Fix: support relative paths and add test
1 parent d824b50 commit 7dd5409

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

orangecontrib/text/corpus.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
print("🧠 Uporabljam corpus.py iz: ", __file__)
2-
3-
41
import os
52
from collections import Counter, defaultdict
63
from copy import copy
@@ -672,8 +669,6 @@ def summarize_corpus(corpus: Corpus) -> PartialSummary:
672669
if corpus.has_tokens()
673670
else "<br/><nobr>Corpus is not preprocessed</nobr>"
674671
)
675-
print(">>> DEBUG: summarize_corpus() pokliče ISO2LANG z vrednostjo:", corpus.language)
676-
# language = ISO2LANG[corpus.language] if corpus.language else "not set"
677672
language = ISO2LANG.get(corpus.language, "not set")
678673
extras += f"<br/><nobr>Language: {language}</nobr>"
679674
return PartialSummary(table_summary.summary, table_summary.details + extras)

orangecontrib/text/widgets/tests/test_owcorpus.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import tempfile
33
import unittest
4+
import shutil
5+
import pickle
46

57
import numpy as np
68
from Orange.data import Table, Domain, StringVariable, ContinuousVariable
@@ -430,6 +432,38 @@ def test_migrate_settings(self):
430432
self.wait_until_finished(widget=widget)
431433
self.assertIsNone(widget.language)
432434

435+
def test_relative_corpus_path_serialization(self):
436+
"""
437+
Test if relative paths are properly saved and reloaded.
438+
"""
439+
# Create a dummy corpus file
440+
with tempfile.TemporaryDirectory() as tmp_dir:
441+
corpus = Corpus.from_file("book-excerpts")
442+
corpus_path = os.path.join(tmp_dir, "test.corpus")
443+
with open(corpus_path, "wb") as f:
444+
pickle.dump(corpus, f)
445+
446+
# Simulate loading the file into widget
447+
self.widget.workflow_file = os.path.join(tmp_dir, "workflow.ows")
448+
self.widget.corpus_path = corpus_path
449+
450+
settings = {}
451+
self.widget.save_settings(settings)
452+
453+
# Simulate moving workflow and corpus to new directory
454+
with tempfile.TemporaryDirectory() as new_dir:
455+
new_corpus = os.path.join(new_dir, "test.corpus")
456+
new_workflow = os.path.join(new_dir, "workflow.ows")
457+
shutil.copy2(corpus_path, new_corpus)
458+
459+
# Simulate loading settings in new widget
460+
restored = self.create_widget(OWCorpus)
461+
restored.workflow_file = new_workflow
462+
settings["corpus_path"] = os.path.relpath(new_corpus, new_dir)
463+
restored.load_settings(settings)
464+
465+
self.assertTrue(os.path.exists(restored.corpus_path))
466+
self.assertTrue(os.path.isabs(restored.corpus_path))
433467

434468
if __name__ == "__main__":
435469
unittest.main()

0 commit comments

Comments
 (0)