From 582867f8dec19fb7a4a359a367a59e720b6710a2 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Sun, 6 Feb 2022 05:47:23 +0100 Subject: [PATCH] Cleaning all flake8 warnings --- src/bootstraparse/modules/environment.py | 2 +- src/bootstraparse/modules/error_mngr.py | 7 +++++-- src/bootstraparse/modules/preparser.py | 17 +++++++++-------- tests/modules/test_error_mngr.py | 6 ++++-- tests/modules/test_preparser.py | 8 ++++---- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/bootstraparse/modules/environment.py b/src/bootstraparse/modules/environment.py index 25d3c10..e0a7767 100644 --- a/src/bootstraparse/modules/environment.py +++ b/src/bootstraparse/modules/environment.py @@ -48,7 +48,7 @@ class Environment: return self._mParams[attribute] elif attribute in self._sParams: return self._sParams[attribute] - else: + else: raise AttributeError(attribute) def __setattr__(self, attribute, value): diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index f11f69b..c53cff4 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -5,7 +5,9 @@ import traceback import sys # Define the error codes -__all__ = ["ParsingError"] + +_ERRORS = ["ParsingError"] +__all__ = _ERRORS+[] def initlogging(filename=None, loglevel="ERROR", filemode='w', handler=None): @@ -52,7 +54,8 @@ class ParsingError(Exception): def __init__(self, message=None, line=None, column=None, file=None): """ - Initializes the ParsingError class with the filename and a line and column number based on the current position in the file (if available) + Initializes the ParsingError class with the filename and a line and column number + based on the current position in the file (if available) """ super().__init__(message) self.line = line diff --git a/src/bootstraparse/modules/preparser.py b/src/bootstraparse/modules/preparser.py index 4868b11..112ebb9 100644 --- a/src/bootstraparse/modules/preparser.py +++ b/src/bootstraparse/modules/preparser.py @@ -1,9 +1,9 @@ # Module for pre-parsing user files in preparation for the parser import os -from bootstraparse.modules import environment from bootstraparse.modules import pathresolver as pr -import rich +# from bootstraparse.modules import environment +# import rich class PreParser: @@ -18,7 +18,7 @@ class PreParser: __env: the environment object path_resolver: the path resolver object, if none is specified, a new one is created with the base path list_of_paths: the list of files that have been imported in this branch of the import tree - dict_of_imports: the dictionary of all imported files + dict_of_imports: Dictionary of all imports made to avoid duplicate file opening / pre-parsing """ if list_of_paths is None: list_of_paths = [] @@ -29,10 +29,10 @@ class PreParser: self.path = path self.name = os.path.basename(path) self.base_path = os.path.dirname(path) - self.relative_path_resolver = pr.PathResolver(path) # Gives absolute path for relative paths - self.list_of_paths = list_of_paths + [self.relative_path_resolver] # List of files in a branch of imports until its end - self.global_dict_of_imports = dict_of_imports # Dictionary of all imports made to avoid duplicate file opening - self.local_dict_of_imports = {} # Dictionary of all local imports made to avoid duplicate file opening + self.relative_path_resolver = pr.PathResolver(path) + self.list_of_paths = list_of_paths + [self.relative_path_resolver] + self.global_dict_of_imports = dict_of_imports + self.local_dict_of_imports = {} # Dictionary of all local imports made to avoid duplicate file opening ? self.file = None def open(self): @@ -104,7 +104,8 @@ class PreParser: """ Returns a string representation of the PreParser object. """ - return "PreParser(path={}, file={}, list_of_paths={}, dict_of_imports={})".format(self.path, self.file, self.list_of_paths, self.global_dict_of_imports) + return "PreParser(path={}, file={}, list_of_paths={}, dict_of_imports={})".format( + self.path, self.file, self.list_of_paths, self.global_dict_of_imports) def __str__(self): """ diff --git a/tests/modules/test_error_mngr.py b/tests/modules/test_error_mngr.py index b1f50f2..8d93fc4 100644 --- a/tests/modules/test_error_mngr.py +++ b/tests/modules/test_error_mngr.py @@ -4,9 +4,11 @@ from importlib import reload from unittest import TestCase import pytest import bootstraparse.modules.error_mngr as error_mngr -from bootstraparse.modules.error_mngr import * +from bootstraparse.modules.error_mngr import ParsingError -all_logging_tests = [(i, j, k) for i in [None, "test.log"] for j in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "NOPE_PARAM"] for k in ["rich", None]] +all_logging_tests = [(i, j, k) for i in [None, "test.log"] + for j in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "NOPE_PARAM"] + for k in ["rich", None]] all_non_blocking_exception_tests = [ (ParsingError("test error", 10, 10, "testfile.bpr")), (ParsingError()) diff --git a/tests/modules/test_preparser.py b/tests/modules/test_preparser.py index 8f761d0..d8c6a5c 100644 --- a/tests/modules/test_preparser.py +++ b/tests/modules/test_preparser.py @@ -65,7 +65,9 @@ Test content Test content""" content_page1 = """Test page1""" content_page2 = """Test page2""" -content_import_list = ["exemple_userfiles/pages/page1.bpr", "exemple_userfiles/pages/page2.bpr", "exemple_userfiles/pages/page1.bpr"] +content_import_list = ["exemple_userfiles/pages/page1.bpr", + "exemple_userfiles/pages/page2.bpr", + "exemple_userfiles/pages/page1.bpr"] final_content = """Test content Test page1 @@ -79,8 +81,6 @@ Test content""" @pytest.fixture(scope="module") def p_index(): return make_false_PreParser("example_userfiles/index.bpr", content_import_list, content_index) -# p_index = preparser.PreParser("example_userfiles/index.bpr", env) -# p_index.open = false_file_open(content_index) ################################################################################ @@ -108,7 +108,7 @@ def test_preparser_content(p_index): p_page1 = make_false_PreParser("exemple_userfiles/pages/page1.bpr", content_import_list, content_page1) assert p_page1.open().readlines() == ["Test page1"] -# + p_page2 = make_false_PreParser("exemple_userfiles/pages/page2.bpr", content_import_list, content_page2) assert p_page2.open().readlines() == ["Test page2"]