Adopted PEP standards (or tried very hard)

This commit is contained in:
Maximilien Rigaut 2022-02-04 02:15:35 +01:00
parent fa4fb78ea8
commit 440e1fd48a
9 changed files with 42 additions and 57 deletions

View File

@ -1,4 +1,4 @@
# Main program, use this to start parsing
def totest():
print("This is a test")
def to_test():
print("This is a test")

View File

@ -3,23 +3,23 @@
import yaml
class ConfigLoader():
class ConfigLoader:
"""
Reads config files.
"""
def __init__(self, configfile):
with open(configfile, "r") as f:
self.loadedconf = yaml.safe_load(f)
self.loaded_conf = yaml.safe_load(f)
def __getitem__(self, item):
try:
return self.loadedconf[item]
return self.loaded_conf[item]
except KeyError:
print("Argument", item, "not found.")
def __repr__(self):
return(self.loadedconf.__repr__())
return self.loaded_conf.__repr__()
class UserConfig(ConfigLoader):

View File

@ -1,9 +1,6 @@
# Module for containing super important variables
import rich
class Environment:
"""
Object containing all the important variables,

View File

@ -3,28 +3,28 @@
import os
class pathresolver():
class PathResolver:
"""
Intialised with a relative path and returns the translated absolute path
Initialised with a relative path and returns the translated absolute path
"""
def __init__(self, basepath):
self.basepath = os.path.normpath(basepath)
def __init__(self, base_path):
self.base_path = os.path.normpath(base_path)
def __call__(self, relativepath='.'):
return self.giveabsolute(relativepath)
def __call__(self, relative_path='.'):
return self.give_absolute(relative_path)
def giveabsolute(self, relativepath='.'):
return os.path.normpath(os.path.join(self.basepath, relativepath))
def give_absolute(self, relative_path='.'):
return os.path.normpath(os.path.join(self.base_path, relative_path))
class boostrapath(pathresolver):
class BoostraPath(PathResolver):
"""
Initialises pathresolver with the path of the bootstraparse installation folder
Initialises PathResolver with the path of the bootstraparse installation folder
"""
def __init__(self):
calculatedpath = os.path.join(__file__, "../../")
super().__init__(calculatedpath)
calculated_path = os.path.join(__file__, "../../")
super().__init__(calculated_path)
bpath = boostrapath()
b_path = BoostraPath()

View File

@ -1,7 +1,7 @@
# Module sequencing the successive actions necessary for website building
import bootstraparse.modules.config as config
from bootstraparse.modules.pathresolver import bpath
from bootstraparse.modules.pathresolver import b_path
def create_website():
@ -24,7 +24,7 @@ def create_config():
"""
Returns globalConfig as an object from parser_config.yml settings.
"""
return config.GlobalConfig(bpath("configs/parser_config.yml"))
return config.GlobalConfig(b_path("configs/parser_config.yml"))
def create_crawler():

View File

@ -1,6 +0,0 @@
from bootstraparse.modules.pathresolver import bpath
import bootstraparse.modules.sitecreator
print(bpath())
print(bootstraparse.modules.sitecreator.create_config())

View File

@ -1,8 +1,7 @@
from logging import exception
import bootstraparse.modules.environment as e
def test_was_initialised():
def test_wasInitialised():
test_check = e.Environment()
for k in test_check._wasInitialised.values():
assert k is False
@ -11,7 +10,7 @@ def test_was_initialised():
def test_integrity_check():
test_check = e.Environment()
custom_test_p = [p for p in test_check._mParams.keys()]
custom_test_v = [False for p in test_check._mParams.values()]
custom_test_v = [False for _ in test_check._mParams.values()]
# Test all False
# rich.inspect(test_check)
@ -40,7 +39,7 @@ def test_integrity_check():
assert test_check.integrity_check() is False
custom_test_v = [True for p in test_check._mParams.values()]
custom_test_v = [True for _ in test_check._mParams.values()]
test_check._wasInitialised = dict(zip(custom_test_p, custom_test_v))
# Test all True
# rich.inspect(test_check)
@ -59,18 +58,18 @@ def test_getter():
assert test_check.test_param == "test_value"
try:
test_check.purposefullyunexistingparameter
test_check.purposefully_non_existing_parameter
except AttributeError:
pass
except Exception:
assert False # Not AttributeError when getting unexisting parameter
assert False # Not AttributeError when getting non-existing parameter
try:
test_check._purposefullyunexistingparameter
test_check._purposefully_non_existing_parameter
except AttributeError:
pass
except Exception:
assert False # Not AttributeError when getting _unexisting parameter
assert False # Not AttributeError when getting underscored non-existing parameter
def test_setter():
@ -86,14 +85,14 @@ def test_setter():
assert test_check.test_param == "second_test_value"
try:
test_check.purposefullyunexistingparameter = "test_value"
test_check.purposefully_non_existing_parameter = "test_value"
except AttributeError:
pass
except Exception:
assert False # Not AttributeError when getting unexisting parameter
assert False # Not AttributeError when getting non-existing parameter
test_check._purposefullyunexistingparameter = "test_value"
assert test_check._purposefullyunexistingparameter == "test_value"
test_check._purposefully_non_existing_parameter = "test_value"
assert test_check._purposefully_non_existing_parameter == "test_value"
if __name__ == "__main__":

View File

@ -1,26 +1,22 @@
import bootstraparse.modules.pathresolver as pathr
import bootstraparse.modules.pathresolver as path_r
import os
import re
pathlike_regexp = r'^([A-z]\:\\|/).+[/\\]src[/\\]bootstraparse[/\\]?$'
path_like_regexp = r'^([A-z]\:\\|/).+[/\\]src[/\\]bootstraparse[/\\]?$'
test_path = '/a/b/c/test'
test_path_win = test_path.replace('/', '\\')
def test_pathresolver():
path = pathr.pathresolver(test_path)
def test_PathResolver():
path = path_r.PathResolver(test_path)
assert path() == os.path.normpath(test_path)
assert path().replace('/', '\\') == test_path_win
assert path().replace('\\', '/') == test_path
def test_boostrapath():
assert re.match(pathlike_regexp, pathr.boostrapath().giveabsolute()) is not None
def test_BoostraPath():
assert re.match(path_like_regexp, path_r.BoostraPath().give_absolute()) is not None
def test_bpath():
assert re.match(pathlike_regexp, pathr.bpath()) is not None
if __name__ == "__main__":
print(test_pathresolver())
def test_b_path():
assert re.match(path_like_regexp, path_r.b_path()) is not None

View File

@ -2,6 +2,5 @@
from bootstraparse import bparse
def test_totest():
assert bparse.totest() is None
def test_to_test():
assert bparse.to_test() is None