Skip to content

Commit

Permalink
Add argument for user-defined dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
euihyun-lee authored Mar 17, 2020
1 parent a74f738 commit ee0bdb4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,34 @@ def test_personalfont_directory_unlocated(self):
self.assertTrue(len(os.listdir("tests/out/")) == 0)
empty_directory("tests/out/")

def test_personaldict(self):
args = [
"python3", "run.py",
"--dict",
"dicts/en.txt",
"-c",
"1",
"--output_dir",
"../tests/out/",
]
subprocess.Popen(args, cwd="trdg/").wait()
self.assertTrue(len(os.listdir("tests/out/")) == 1)
empty_directory("tests/out/")

def test_personaldict_unlocated(self):
args = [
"python3", "run.py",
"--dict",
"dicts/unlocatedDict.txt",
"-c",
"1",
"--output_dir",
"../tests/out/",
]
subprocess.Popen(args, cwd="trdg/").wait()
self.assertTrue(len(os.listdir("tests/out/")) == 0)
empty_directory("tests/out/")

# def test_word_count(self):
# args = ['python3', 'run.py', '-c', '1', '-w', '5']
# subprocess.Popen(args, cwd="trdg/").wait()
Expand Down
13 changes: 12 additions & 1 deletion trdg/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def parse_arguments():
nargs="?",
help="Generate upper or lowercase only. arguments: upper or lower. Example: --case upper",
)
parser.add_argument(
"-dt", "--dict", type=str, nargs="?", help="Define dictionary to be used"
)
return parser.parse_args()


Expand All @@ -304,7 +307,15 @@ def main():
raise

# Creating word list
lang_dict = load_dict(args.language)
if args.dict:
lang_dict = []
if os.path.isfile(args.dict):
with open(args.dict, "r", encoding="utf8", errors="ignore") as d:
lang_dict = [l for l in d.read().splitlines() if len(l) > 0]
else:
sys.exit("Cannot open dict")
else:
lang_dict = load_dict(args.language)

# Create font (path) list
if args.font_dir:
Expand Down

0 comments on commit ee0bdb4

Please sign in to comment.