Fixed test units for preparser

This commit is contained in:
Maximilien Rigaut 2022-03-04 14:27:09 +01:00
parent f45b53b0c1
commit 3d3c8364e7
2 changed files with 30 additions and 22 deletions

View File

@ -97,7 +97,7 @@ class PreParser:
# parse_import_list()
# make_import_list()
# export_with_imports()
# self.current_origin_for_read = self.file_with_all_imports
self.current_origin_for_read = self.file_with_all_imports
# return self.current_origin_for_read
pass
@ -108,7 +108,7 @@ class PreParser:
# TODO: Implement this
# Do all replacements
#
# self.current_origin_for_read = self.file_with_all_replacements
self.current_origin_for_read = self.file_with_all_replacements
# return self.current_origin_for_read
pass
@ -214,21 +214,22 @@ class PreParser:
and replaces shortcuts and images calls with appropriate html
:return: a table of occurrences and their lines
"""
line_count = 0
temp_file = self.file_with_all_replacements
for line in self.readlines():
results = syntax.alias.parse_string(line)
if results:
temp_file.writelines(self.get_alias_from_config(results.alias_name))
else:
results = syntax.inage.parse_string(line)
if results:
temp_file.writelines(self.get_picture_from_config(results.image_name))
else:
temp_file.writelines(line)
line_count += 1
self.replacements_done = True
return temp_file
pass
# line_count = 0
# temp_file = self.file_with_all_replacements
# for line in self.readlines():
# results = syntax.alias.parse_string(line)
# if results:
# temp_file.writelines(self.get_alias_from_config(results.alias_name))
# else:
# results = syntax.inage.parse_string(line)
# if results:
# temp_file.writelines(self.get_picture_from_config(results.image_name))
# else:
# temp_file.writelines(line)
# line_count += 1
# self.replacements_done = True
# return temp_file
def get_alias_from_config(self, shortcut):
"""

View File

@ -2,6 +2,7 @@
import os
import pathlib
import tempfile
from io import StringIO
import pytest
# import rich
@ -97,6 +98,7 @@ def make_new_file(path, content="", mode="w+"):
def assert_readlines_equals(lines1, lines2):
for line1, line2 in zip(lines1, lines2):
assert line1.strip("\n") == line2.strip("\n")
return True
@pytest.mark.parametrize("path, line_found", [
@ -239,15 +241,20 @@ def test_get_all_lines():
testfile = temp_name("index.bpr")
assert os.path.exists(testfile)
pp = preparser.PreParser(testfile, env)
assert pp.get_all_lines() == content_index.split("\n")
assert_readlines_equals(pp.get_all_lines(), content_index.split("\n"))
# To test we are getting the right file
pp.file_with_all_imports, temp = StringIO("12"), pp.file_with_all_imports
pp.do_imports()
pp.file_with_all_imports, temp = 12, pp.file_with_all_imports # To test we are getting the right file
assert pp.get_all_lines() == 12
assert pp.get_all_lines() == ['12']
pp.file_with_all_imports = temp
# To test we are getting the right file
pp.file_with_all_replacements, temp = StringIO("123"), pp.file_with_all_replacements
pp.do_replacements()
pp.file_with_all_replacements, temp = 123, pp.file_with_all_replacements # To test we are getting the right file
assert pp.get_all_lines() == 123
assert pp.get_all_lines() == ["123"]
pp.file_with_all_replacements = temp
assert pp.readlines() != pp.get_all_lines()
@pytest.mark.xfail(reason="Not implemented")