Skip to content

Commit 54e1400

Browse files
committed
Remove tests which require reading files because they don't seem to work. Now existing functions parse_file and huffman still don't have doctests but all new functions, and existing function build_tree, do have doctests
1 parent 8eea4b8 commit 54e1400

File tree

3 files changed

+1
-36
lines changed

3 files changed

+1
-36
lines changed

compression/huffman.py

+1-33
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ def parse_string(string: str) -> list[Letter]:
5353
def parse_file(file_path: str) -> list[Letter]:
5454
"""
5555
Read file and return a list of Letter objects storing frequency
56-
>>> PREFIX = _get_test_data_path_prefix()
57-
>>> test_file_path_in1 = f"{PREFIX}text_data/text_original.txt"
58-
>>> out1 = parse_file(test_file_path_in1)
59-
>>> out1
60-
[T:1, h:1, a:1, e:1, i:2, t:2, s:3, :3, .:3]
6156
"""
6257
chars: dict[str, Letter] = {}
6358
with open(file_path) as input_file:
@@ -112,7 +107,6 @@ def traverse_tree(root: Letter | TreeNode, bitstring: str = "") -> list[Letter]:
112107
"""
113108
Recursively traverse the Huffman Tree to set each
114109
Letter's bitstring dictionary, and return the list of Letters
115-
>>> PREFIX = _get_test_data_path_prefix()
116110
>>> root_in1 = build_tree(parse_string("goose"))
117111
>>> out1 = traverse_tree(root_in1, "")
118112
>>> out1
@@ -125,7 +119,7 @@ def traverse_tree(root: Letter | TreeNode, bitstring: str = "") -> list[Letter]:
125119
'10'
126120
>>> out1[3].bitstring['o']
127121
'11'
128-
>>> root_in2 = build_tree(parse_file(f"{PREFIX}text_data/text_original.txt"))
122+
>>> root_in2 = build_tree(parse_string("This is a test..."))
129123
>>> out2 = traverse_tree(root_in2)
130124
>>> out2
131125
[.:3, i:2, t:2, T:1, h:1, a:1, e:1, s:3, :3]
@@ -168,18 +162,6 @@ def huffman(
168162
Parse the file, Huffman Code it and print the result
169163
to the given output_file, with each bitstring
170164
separated by sep parameter
171-
>>> PREFIX = _get_test_data_path_prefix()
172-
>>> huffman(f"{PREFIX}text_data/text_original.txt", sep="_")
173-
Huffman Coding of text_data/text_original.txt:
174-
1000_1001_010_110_111_010_110_111_1010_111_011_1011_110_011_00_00_00_
175-
>>> with open(f"{PREFIX}text_data/text_huffman.txt", "w") as output_file_in1:
176-
... huffman(f"{PREFIX}text_data/text_original.txt", sep="",
177-
... output_file=output_file_in1)
178-
>>> with open(f"{PREFIX}text_data/text_huffman.txt") as output_file_out1:
179-
... print(output_file_out1.read())
180-
Huffman Coding of text_data/text_original.txt:
181-
1000100101011011101011011110101110111011110011000000
182-
<BLANKLINE>
183165
"""
184166
letters_list = parse_file(file_path)
185167
root = build_tree(letters_list)
@@ -193,20 +175,6 @@ def huffman(
193175
print(file=output_file)
194176

195177

196-
def _get_test_data_path_prefix():
197-
try:
198-
with open("compression/text_data/text_original.txt"):
199-
pass
200-
return "copmression/"
201-
except FileNotFoundError:
202-
try:
203-
with open("text_data/text_original.txt"):
204-
pass
205-
return ""
206-
except FileNotFoundError:
207-
raise FileNotFoundError("Could not locate testing data")
208-
209-
210178
if __name__ == "__main__":
211179
if len(sys.argv) < 2:
212180
# if no file path given, test module

compression/text_data/text_huffman.txt

-2
This file was deleted.

compression/text_data/text_original.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)