Cleaning all flake8 warnings

This commit is contained in:
Maximilien Rigaut 2022-02-06 05:47:23 +01:00
parent 1bed0cc8c8
commit 582867f8de
5 changed files with 23 additions and 17 deletions

View File

@ -5,7 +5,9 @@ import traceback
import sys import sys
# Define the error codes # Define the error codes
__all__ = ["ParsingError"]
_ERRORS = ["ParsingError"]
__all__ = _ERRORS+[]
def initlogging(filename=None, loglevel="ERROR", filemode='w', handler=None): 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): 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) super().__init__(message)
self.line = line self.line = line

View File

@ -1,9 +1,9 @@
# Module for pre-parsing user files in preparation for the parser # Module for pre-parsing user files in preparation for the parser
import os import os
from bootstraparse.modules import environment
from bootstraparse.modules import pathresolver as pr from bootstraparse.modules import pathresolver as pr
import rich # from bootstraparse.modules import environment
# import rich
class PreParser: class PreParser:
@ -18,7 +18,7 @@ class PreParser:
__env: the environment object __env: the environment object
path_resolver: the path resolver object, if none is specified, a new one is created with the base path 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 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: if list_of_paths is None:
list_of_paths = [] list_of_paths = []
@ -29,10 +29,10 @@ class PreParser:
self.path = path self.path = path
self.name = os.path.basename(path) self.name = os.path.basename(path)
self.base_path = os.path.dirname(path) self.base_path = os.path.dirname(path)
self.relative_path_resolver = pr.PathResolver(path) # Gives absolute path for relative paths self.relative_path_resolver = pr.PathResolver(path)
self.list_of_paths = list_of_paths + [self.relative_path_resolver] # List of files in a branch of imports until its end self.list_of_paths = list_of_paths + [self.relative_path_resolver]
self.global_dict_of_imports = dict_of_imports # Dictionary of all imports made to avoid duplicate file opening 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.local_dict_of_imports = {} # Dictionary of all local imports made to avoid duplicate file opening ?
self.file = None self.file = None
def open(self): def open(self):
@ -104,7 +104,8 @@ class PreParser:
""" """
Returns a string representation of the PreParser object. 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): def __str__(self):
""" """

View File

@ -4,9 +4,11 @@ from importlib import reload
from unittest import TestCase from unittest import TestCase
import pytest import pytest
import bootstraparse.modules.error_mngr as error_mngr 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 = [ all_non_blocking_exception_tests = [
(ParsingError("test error", 10, 10, "testfile.bpr")), (ParsingError("test error", 10, 10, "testfile.bpr")),
(ParsingError()) (ParsingError())

View File

@ -65,7 +65,9 @@ Test content
Test content""" Test content"""
content_page1 = """Test page1""" content_page1 = """Test page1"""
content_page2 = """Test page2""" 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 final_content = """Test content
Test page1 Test page1
@ -79,8 +81,6 @@ Test content"""
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def p_index(): def p_index():
return make_false_PreParser("example_userfiles/index.bpr", content_import_list, content_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) p_page1 = make_false_PreParser("exemple_userfiles/pages/page1.bpr", content_import_list, content_page1)
assert p_page1.open().readlines() == ["Test page1"] assert p_page1.open().readlines() == ["Test page1"]
#
p_page2 = make_false_PreParser("exemple_userfiles/pages/page2.bpr", content_import_list, content_page2) p_page2 = make_false_PreParser("exemple_userfiles/pages/page2.bpr", content_import_list, content_page2)
assert p_page2.open().readlines() == ["Test page2"] assert p_page2.open().readlines() == ["Test page2"]