Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored file read function into file_utils
- Loading branch information
Showing
3 changed files
with
13 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,23 +1,17 @@ | |||
import os.path | import os.path | ||
import aml | import aml | ||
import file_utils | |||
|
|
||
self_dir = os.path.dirname(__file__) | self_dir = os.path.dirname(__file__) | ||
input_dir = os.path.join(self_dir, 'fixtures', 'input') | input_dir = os.path.join(self_dir, 'fixtures', 'input') | ||
output_dir = os.path.join(self_dir, 'fixtures', 'output') | output_dir = os.path.join(self_dir, 'fixtures', 'output') | ||
|
|
||
tests = ['singleline-text', 'multiline-text'] | tests = ['singleline-text', 'multiline-text'] | ||
|
|
||
def read_file(path): | |||
file = open(path) | |||
try: | |||
return file.read() | |||
finally: | |||
file.close() | |||
|
|||
for test in tests: | for test in tests: | ||
input = read_file(os.path.join(input_dir, test + '.at')) | input = file_utils.read_file(os.path.join(input_dir, test + '.at')) | ||
actual_output = aml.convert_text(input) | actual_output = aml.convert_text(input) | ||
expected_output = read_file(os.path.join(output_dir, test + '.jt')) | expected_output = file_utils.read_file(os.path.join(output_dir, test + '.jt')) | ||
#print actual_output | #print actual_output | ||
#print expected_output | #print expected_output | ||
assert actual_output == expected_output | assert actual_output == expected_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
def read_file(path): | |||
file = open(path) | |||
try: | |||
contents = file.read() | |||
finally: | |||
file.close() | |||
return contents |