Skip to content

Commit ee0bdb4

Browse files
authored
Add argument for user-defined dictionary
1 parent a74f738 commit ee0bdb4

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

tests.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,34 @@ def test_personalfont_directory_unlocated(self):
831831
self.assertTrue(len(os.listdir("tests/out/")) == 0)
832832
empty_directory("tests/out/")
833833

834+
def test_personaldict(self):
835+
args = [
836+
"python3", "run.py",
837+
"--dict",
838+
"dicts/en.txt",
839+
"-c",
840+
"1",
841+
"--output_dir",
842+
"../tests/out/",
843+
]
844+
subprocess.Popen(args, cwd="trdg/").wait()
845+
self.assertTrue(len(os.listdir("tests/out/")) == 1)
846+
empty_directory("tests/out/")
847+
848+
def test_personaldict_unlocated(self):
849+
args = [
850+
"python3", "run.py",
851+
"--dict",
852+
"dicts/unlocatedDict.txt",
853+
"-c",
854+
"1",
855+
"--output_dir",
856+
"../tests/out/",
857+
]
858+
subprocess.Popen(args, cwd="trdg/").wait()
859+
self.assertTrue(len(os.listdir("tests/out/")) == 0)
860+
empty_directory("tests/out/")
861+
834862
# def test_word_count(self):
835863
# args = ['python3', 'run.py', '-c', '1', '-w', '5']
836864
# subprocess.Popen(args, cwd="trdg/").wait()

trdg/run.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ def parse_arguments():
285285
nargs="?",
286286
help="Generate upper or lowercase only. arguments: upper or lower. Example: --case upper",
287287
)
288+
parser.add_argument(
289+
"-dt", "--dict", type=str, nargs="?", help="Define dictionary to be used"
290+
)
288291
return parser.parse_args()
289292

290293

@@ -304,7 +307,15 @@ def main():
304307
raise
305308

306309
# Creating word list
307-
lang_dict = load_dict(args.language)
310+
if args.dict:
311+
lang_dict = []
312+
if os.path.isfile(args.dict):
313+
with open(args.dict, "r", encoding="utf8", errors="ignore") as d:
314+
lang_dict = [l for l in d.read().splitlines() if len(l) > 0]
315+
else:
316+
sys.exit("Cannot open dict")
317+
else:
318+
lang_dict = load_dict(args.language)
308319

309320
# Create font (path) list
310321
if args.font_dir:

0 commit comments

Comments
 (0)