Adopted PEP standards (or tried very hard)
This commit is contained in:
parent
fa4fb78ea8
commit
440e1fd48a
|
|
@ -1,4 +1,4 @@
|
||||||
# Main program, use this to start parsing
|
# Main program, use this to start parsing
|
||||||
|
|
||||||
def totest():
|
def to_test():
|
||||||
print("This is a test")
|
print("This is a test")
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,23 @@
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class ConfigLoader():
|
class ConfigLoader:
|
||||||
"""
|
"""
|
||||||
Reads config files.
|
Reads config files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, configfile):
|
def __init__(self, configfile):
|
||||||
with open(configfile, "r") as f:
|
with open(configfile, "r") as f:
|
||||||
self.loadedconf = yaml.safe_load(f)
|
self.loaded_conf = yaml.safe_load(f)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
try:
|
try:
|
||||||
return self.loadedconf[item]
|
return self.loaded_conf[item]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("Argument", item, "not found.")
|
print("Argument", item, "not found.")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return(self.loadedconf.__repr__())
|
return self.loaded_conf.__repr__()
|
||||||
|
|
||||||
|
|
||||||
class UserConfig(ConfigLoader):
|
class UserConfig(ConfigLoader):
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
# Module for containing super important variables
|
# Module for containing super important variables
|
||||||
|
|
||||||
|
|
||||||
import rich
|
|
||||||
|
|
||||||
|
|
||||||
class Environment:
|
class Environment:
|
||||||
"""
|
"""
|
||||||
Object containing all the important variables,
|
Object containing all the important variables,
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,28 @@
|
||||||
import os
|
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):
|
def __init__(self, base_path):
|
||||||
self.basepath = os.path.normpath(basepath)
|
self.base_path = os.path.normpath(base_path)
|
||||||
|
|
||||||
def __call__(self, relativepath='.'):
|
def __call__(self, relative_path='.'):
|
||||||
return self.giveabsolute(relativepath)
|
return self.give_absolute(relative_path)
|
||||||
|
|
||||||
def giveabsolute(self, relativepath='.'):
|
def give_absolute(self, relative_path='.'):
|
||||||
return os.path.normpath(os.path.join(self.basepath, relativepath))
|
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):
|
def __init__(self):
|
||||||
calculatedpath = os.path.join(__file__, "../../")
|
calculated_path = os.path.join(__file__, "../../")
|
||||||
super().__init__(calculatedpath)
|
super().__init__(calculated_path)
|
||||||
|
|
||||||
|
|
||||||
bpath = boostrapath()
|
b_path = BoostraPath()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Module sequencing the successive actions necessary for website building
|
# Module sequencing the successive actions necessary for website building
|
||||||
|
|
||||||
import bootstraparse.modules.config as config
|
import bootstraparse.modules.config as config
|
||||||
from bootstraparse.modules.pathresolver import bpath
|
from bootstraparse.modules.pathresolver import b_path
|
||||||
|
|
||||||
|
|
||||||
def create_website():
|
def create_website():
|
||||||
|
|
@ -24,7 +24,7 @@ def create_config():
|
||||||
"""
|
"""
|
||||||
Returns globalConfig as an object from parser_config.yml settings.
|
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():
|
def create_crawler():
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
from bootstraparse.modules.pathresolver import bpath
|
|
||||||
import bootstraparse.modules.sitecreator
|
|
||||||
|
|
||||||
|
|
||||||
print(bpath())
|
|
||||||
print(bootstraparse.modules.sitecreator.create_config())
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
from logging import exception
|
|
||||||
import bootstraparse.modules.environment as e
|
import bootstraparse.modules.environment as e
|
||||||
|
|
||||||
|
|
||||||
def test_was_initialised():
|
def test_wasInitialised():
|
||||||
test_check = e.Environment()
|
test_check = e.Environment()
|
||||||
for k in test_check._wasInitialised.values():
|
for k in test_check._wasInitialised.values():
|
||||||
assert k is False
|
assert k is False
|
||||||
|
|
@ -11,7 +10,7 @@ def test_was_initialised():
|
||||||
def test_integrity_check():
|
def test_integrity_check():
|
||||||
test_check = e.Environment()
|
test_check = e.Environment()
|
||||||
custom_test_p = [p for p in test_check._mParams.keys()]
|
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
|
# Test all False
|
||||||
# rich.inspect(test_check)
|
# rich.inspect(test_check)
|
||||||
|
|
||||||
|
|
@ -40,7 +39,7 @@ def test_integrity_check():
|
||||||
|
|
||||||
assert test_check.integrity_check() is False
|
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_check._wasInitialised = dict(zip(custom_test_p, custom_test_v))
|
||||||
# Test all True
|
# Test all True
|
||||||
# rich.inspect(test_check)
|
# rich.inspect(test_check)
|
||||||
|
|
@ -59,18 +58,18 @@ def test_getter():
|
||||||
assert test_check.test_param == "test_value"
|
assert test_check.test_param == "test_value"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
test_check.purposefullyunexistingparameter
|
test_check.purposefully_non_existing_parameter
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
assert False # Not AttributeError when getting unexisting parameter
|
assert False # Not AttributeError when getting non-existing parameter
|
||||||
|
|
||||||
try:
|
try:
|
||||||
test_check._purposefullyunexistingparameter
|
test_check._purposefully_non_existing_parameter
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
assert False # Not AttributeError when getting _unexisting parameter
|
assert False # Not AttributeError when getting underscored non-existing parameter
|
||||||
|
|
||||||
|
|
||||||
def test_setter():
|
def test_setter():
|
||||||
|
|
@ -86,14 +85,14 @@ def test_setter():
|
||||||
assert test_check.test_param == "second_test_value"
|
assert test_check.test_param == "second_test_value"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
test_check.purposefullyunexistingparameter = "test_value"
|
test_check.purposefully_non_existing_parameter = "test_value"
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
assert False # Not AttributeError when getting unexisting parameter
|
assert False # Not AttributeError when getting non-existing parameter
|
||||||
|
|
||||||
test_check._purposefullyunexistingparameter = "test_value"
|
test_check._purposefully_non_existing_parameter = "test_value"
|
||||||
assert test_check._purposefullyunexistingparameter == "test_value"
|
assert test_check._purposefully_non_existing_parameter == "test_value"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,22 @@
|
||||||
import bootstraparse.modules.pathresolver as pathr
|
import bootstraparse.modules.pathresolver as path_r
|
||||||
import os
|
import os
|
||||||
import re
|
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 = '/a/b/c/test'
|
||||||
test_path_win = test_path.replace('/', '\\')
|
test_path_win = test_path.replace('/', '\\')
|
||||||
|
|
||||||
|
|
||||||
def test_pathresolver():
|
def test_PathResolver():
|
||||||
path = pathr.pathresolver(test_path)
|
path = path_r.PathResolver(test_path)
|
||||||
assert path() == os.path.normpath(test_path)
|
assert path() == os.path.normpath(test_path)
|
||||||
assert path().replace('/', '\\') == test_path_win
|
assert path().replace('/', '\\') == test_path_win
|
||||||
assert path().replace('\\', '/') == test_path
|
assert path().replace('\\', '/') == test_path
|
||||||
|
|
||||||
|
|
||||||
def test_boostrapath():
|
def test_BoostraPath():
|
||||||
assert re.match(pathlike_regexp, pathr.boostrapath().giveabsolute()) is not None
|
assert re.match(path_like_regexp, path_r.BoostraPath().give_absolute()) is not None
|
||||||
|
|
||||||
|
|
||||||
def test_bpath():
|
def test_b_path():
|
||||||
assert re.match(pathlike_regexp, pathr.bpath()) is not None
|
assert re.match(path_like_regexp, path_r.b_path()) is not None
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print(test_pathresolver())
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,5 @@
|
||||||
from bootstraparse import bparse
|
from bootstraparse import bparse
|
||||||
|
|
||||||
|
|
||||||
def test_totest():
|
def test_to_test():
|
||||||
assert bparse.totest() is None
|
assert bparse.to_test() is None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue