From 3d3c8364e78e2d6a8da2e23301d839c9f1dd9bd1 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Fri, 4 Mar 2022 14:27:09 +0100 Subject: [PATCH] Fixed test units for preparser --- src/bootstraparse/modules/preparser.py | 35 +++++++++++++------------- tests/modules/test_preparser.py | 17 +++++++++---- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/bootstraparse/modules/preparser.py b/src/bootstraparse/modules/preparser.py index bda9000..05dc57d 100644 --- a/src/bootstraparse/modules/preparser.py +++ b/src/bootstraparse/modules/preparser.py @@ -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): """ diff --git a/tests/modules/test_preparser.py b/tests/modules/test_preparser.py index 7a7919a..e6567d9 100644 --- a/tests/modules/test_preparser.py +++ b/tests/modules/test_preparser.py @@ -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")