Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\[Title should should be clear and concise, like:

Adds ___ to ___

Fixes # ___ in ___ \]
### Summary
\[Summarize what this pull request does, i.e. fixes __ or adds __, a nifty feature.\]

### Description
\[Go into more detail about what the pull request does. For example, reference
opened/closed issues or detail reasoning for adding a feature.\]

### Team Notifications
\[Who should be notified to review the pull request. Likely @JoseALermaIII\]
2 changes: 1 addition & 1 deletion src/ch03/p1_digram_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def main():
print(f'Analyzing: {word}\n')
print('In the Ubuntu default `american-english` dictionary, these are\n'
'the digram counts for the above word:')
digram_count = digram_counter(word)
digram_count = digram_counter(word, DICTIONARY_FILE_PATH)
print_bar_chart(digram_count)
top_digram = sorted(digram_count.keys())[0]
print(f'\nThe "{top_digram}" digram occurs {digram_count[top_digram]} '
Expand Down
17 changes: 17 additions & 0 deletions tests/data/ch03/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ boson
c
cat
catatonic
cool
coot
cover
coverage
d
dog
dirge
Expand All @@ -23,8 +27,11 @@ gecko
gopher
h
heels
hello
hemoglobin
hermit
hoot
hover
i
imp
indigo
Expand All @@ -40,6 +47,8 @@ l
lemon
less
lime
loss
lovely
m
mesolithic
moonlight
Expand All @@ -55,17 +64,23 @@ pat
patti
penny
pepper
pillow
pip
pit
pita
pitt
polo
pool
q
quasar
quark
r
riddle
rubber
s
salve
salvo
servlet
set
slight
swift
Expand All @@ -85,6 +100,8 @@ umbra
v
venus
vertiginous
vocal
vocation
w
whip
whirl
Expand Down
18 changes: 9 additions & 9 deletions tests/data/ch03/main/digram_counter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Analyzing: volvo

In the Ubuntu default `american-english` dictionary, these are
the digram counts for the above word:
Counter({'lo': 3554,
'ol': 3376,
'oo': 2265,
'ov': 1223,
'vo': 603,
'lv': 260,
'vv': 21,
'vl': 12})
Counter({'lo': 7,
'oo': 6,
'ol': 5,
'ov': 4,
'vo': 3,
'lv': 2,
'vl': 1,
'vv': 0})

The "lo" digram occurs 3554 times!
The "lo" digram occurs 7 times!
2 changes: 2 additions & 0 deletions tests/test_chapter03.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def test_digram_counter(self):
self.assertDictEqual(count, test_count)

@unittest.mock.patch('sys.stdout', new_callable=StringIO)
@unittest.mock.patch('src.ch03.p1_digram_counter.DICTIONARY_FILE_PATH',
'tests/data/ch03/dictionary.txt')
def test_main(self, mock_stdout):
"""Test demo main function."""
digram_counter.main()
Expand Down
18 changes: 18 additions & 0 deletions tests/test_chapter06.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import os
import unittest.mock
from io import StringIO

from docx import Document
from docx.shared import RGBColor

import src.ch06.p1_invisible_ink as invisible_ink


Expand Down Expand Up @@ -69,6 +73,13 @@ def test_write_invisible(self):
self.assertEqual(len(all_text), len(output_text))
for line in output_text:
self.assertIn(line, all_text)
# Check color
doc = Document(output_file)
for paragraph in doc.paragraphs:
if paragraph.text in ciphertext:
for run in paragraph.runs:
self.assertEqual(run.font.color.rgb,
RGBColor(255, 255, 255))
os.remove(output_file)
# Test custom template and filename.
template_file = os.path.normpath('tests/data/ch06/template.docx')
Expand All @@ -81,6 +92,13 @@ def test_write_invisible(self):
self.assertEqual(len(all_text), len(output_text))
for line in output_text:
self.assertIn(line, all_text)
# Check color
doc = Document(output_file)
for paragraph in doc.paragraphs:
if paragraph.text in ciphertext:
for run in paragraph.runs:
self.assertEqual(run.font.color.rgb,
RGBColor(255, 255, 255))
os.remove(output_file)
# Test error.
faketext = invisible_ink.get_text(fakefile)
Expand Down