Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument dict #124

Merged
merged 2 commits into from Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests.py
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
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