Skip to content

Commit

Permalink
fixed some tests (code was not ported to Python 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bboc committed Feb 13, 2022
1 parent eef28ef commit 186965a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions mdimg/image_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ def __init__(self, root):
self.missing_counter = defaultdict(lambda: defaultdict(int))

self.languages = self._find_languages()

self._build_repo_structure()

class DuplicateImageException(Exception):
def message(self, path, line_number):
return dedent("""
ambiguous image reference in "{}", line {}:
"{}" --> "{}" """).format(path, line_number, self[0], repr(self[1]))
"{}" --> "{}" """).format(path, line_number, self.args[0], repr(self.args[1]))

class ImageNotFoundException(Exception):
def message(self, path, line_number):
return dedent("""
image not found in file "{}", line {}:
image reference: "{}" """).format(path, line_number, self[0])
image reference: "{}" """).format(path, line_number, self.args[0])

def _find_languages(self):
# TODO: there must be a better way than using os.walk this way?
Expand Down
8 changes: 4 additions & 4 deletions mdimg/image_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def process(self):
original = self.path
print('original', original)
print('target', target_path)
with file(original, 'r') as source:
with file(target_path, 'w+') as target:
with open(original, 'r') as source:
with open(target_path, 'w+') as target:
self.parse_file(source, target.write)

if self.keep_backup:
Expand Down Expand Up @@ -147,8 +147,8 @@ def _update_image_ref(m):
self.document_has_errors = True
print(e.message(self.path, line_number), file=self.ERROR_OUT)
writer('{>>ERROR--ambiguous image reference:<<}\n')
for idx, variant in enumerate(e[1]):
for idx, variant in enumerate(e.args[1]):
writer('{>>variant ' + str(idx) + ':<<}\n')
writer(line.replace(e[0], variant))
writer(line.replace(e.args[0], variant))
writer('{>>original reference:<<}\n')
writer(line)
4 changes: 2 additions & 2 deletions tests/mdslides/macro_tests.py → tests/macro_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def setUp(self):

def test_replace(self):

def macro1():
def macro1(*args, **kwargs):
return "<replaced m1>"

def macro2(param1):
def macro2(*args, **kwargs):
return "<replaced m2>"

def macro_bar_foo(*args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions tests/mdimg/image_update_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def setUp(self):

def compare_results(self, result_file, correct_file):
"""Compare the actual result with the correct result."""
with file(correct_file, 'r+') as correct:
with open(correct_file, 'r+') as correct:
c = correct.readlines()
with file(result_file, 'r+') as result:
with open(result_file, 'r+') as result:
r = result.readlines()
self.assertEqual(c, r)

Expand Down

0 comments on commit 186965a

Please sign in to comment.