Fixed test units for preparser
This commit is contained in:
parent
f45b53b0c1
commit
3d3c8364e7
|
|
@ -97,7 +97,7 @@ class PreParser:
|
||||||
# parse_import_list()
|
# parse_import_list()
|
||||||
# make_import_list()
|
# make_import_list()
|
||||||
# export_with_imports()
|
# 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
|
# return self.current_origin_for_read
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ class PreParser:
|
||||||
# TODO: Implement this
|
# TODO: Implement this
|
||||||
# Do all replacements
|
# 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
|
# return self.current_origin_for_read
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -214,21 +214,22 @@ class PreParser:
|
||||||
and replaces shortcuts and images calls with appropriate html
|
and replaces shortcuts and images calls with appropriate html
|
||||||
:return: a table of occurrences and their lines
|
:return: a table of occurrences and their lines
|
||||||
"""
|
"""
|
||||||
line_count = 0
|
pass
|
||||||
temp_file = self.file_with_all_replacements
|
# line_count = 0
|
||||||
for line in self.readlines():
|
# temp_file = self.file_with_all_replacements
|
||||||
results = syntax.alias.parse_string(line)
|
# for line in self.readlines():
|
||||||
if results:
|
# results = syntax.alias.parse_string(line)
|
||||||
temp_file.writelines(self.get_alias_from_config(results.alias_name))
|
# if results:
|
||||||
else:
|
# temp_file.writelines(self.get_alias_from_config(results.alias_name))
|
||||||
results = syntax.inage.parse_string(line)
|
# else:
|
||||||
if results:
|
# results = syntax.inage.parse_string(line)
|
||||||
temp_file.writelines(self.get_picture_from_config(results.image_name))
|
# if results:
|
||||||
else:
|
# temp_file.writelines(self.get_picture_from_config(results.image_name))
|
||||||
temp_file.writelines(line)
|
# else:
|
||||||
line_count += 1
|
# temp_file.writelines(line)
|
||||||
self.replacements_done = True
|
# line_count += 1
|
||||||
return temp_file
|
# self.replacements_done = True
|
||||||
|
# return temp_file
|
||||||
|
|
||||||
def get_alias_from_config(self, shortcut):
|
def get_alias_from_config(self, shortcut):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
# import rich
|
# import rich
|
||||||
|
|
@ -97,6 +98,7 @@ def make_new_file(path, content="", mode="w+"):
|
||||||
def assert_readlines_equals(lines1, lines2):
|
def assert_readlines_equals(lines1, lines2):
|
||||||
for line1, line2 in zip(lines1, lines2):
|
for line1, line2 in zip(lines1, lines2):
|
||||||
assert line1.strip("\n") == line2.strip("\n")
|
assert line1.strip("\n") == line2.strip("\n")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("path, line_found", [
|
@pytest.mark.parametrize("path, line_found", [
|
||||||
|
|
@ -239,15 +241,20 @@ def test_get_all_lines():
|
||||||
testfile = temp_name("index.bpr")
|
testfile = temp_name("index.bpr")
|
||||||
assert os.path.exists(testfile)
|
assert os.path.exists(testfile)
|
||||||
pp = preparser.PreParser(testfile, env)
|
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.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
|
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.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
|
pp.file_with_all_replacements = temp
|
||||||
|
assert pp.readlines() != pp.get_all_lines()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="Not implemented")
|
@pytest.mark.xfail(reason="Not implemented")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue