diff --git a/pyproject.toml b/pyproject.toml index 2cfaf4c..521467a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,14 +36,16 @@ src = ["src"] # consider folder as first-party import [tool.ruff.lint] extend-select = [ - "B", # flake8-bugbear - "I", # isort - "N", # pep8 naming - "SIM", # flake8-simplify, for simplified code - "PTH", # pathlib (instead of os.path) - "W", # warning - "T2", # flake8-print (avoiding prints) - "S", # bandit, security checks + "B", # flake8-bugbear + "D212", # docstring first line should end with period + "D415", # multiline docstring should start at first line + "I", # isort + "N", # pep8 naming + "PTH", # pathlib (instead of os.path) + "S", # bandit, security checks + "SIM", # flake8-simplify, for simplified code + "T2", # flake8-print (avoiding prints) + "W", # warning ] ignore = [ "N818", # error suffix in exception names @@ -52,6 +54,8 @@ ignore = [ ] [tool.ruff.lint.per-file-ignores] -"**/tests/*" = ["T"] +"**/tests/*" = [ + "S101", # Use of `assert` detected + "T", # flake8-print (avoiding prints) +] "examples/*" = ["T"] -"**/tests*" = ["S101"] # Use of `assert` detected diff --git a/src/mijnbib/login_handlers.py b/src/mijnbib/login_handlers.py index 763bef1..c867a12 100644 --- a/src/mijnbib/login_handlers.py +++ b/src/mijnbib/login_handlers.py @@ -32,7 +32,7 @@ def login(self) -> mechanize.Browser: class LoginByForm(LoginHandler): - """Uses mechanize library to log in""" + """Uses mechanize library to log in.""" def login(self) -> mechanize.Browser: response = self._log_in() @@ -132,7 +132,7 @@ def _log_in(self): def _validate_logged_in(html: str) -> None: - """Raises AuthenticationError if login failed.""" + """Raise AuthenticationError if login failed.""" _log.debug("Checking if login is successful ...") if "Profiel" not in html: if ( diff --git a/src/mijnbib/mijnbibliotheek.py b/src/mijnbib/mijnbibliotheek.py index 4a37ce9..fd29d54 100644 --- a/src/mijnbib/mijnbibliotheek.py +++ b/src/mijnbib/mijnbibliotheek.py @@ -1,5 +1,5 @@ -""" -Webscraper module for interacting with the mijn.bibliotheek.be website. +"""Webscraper module for interacting with the mijn.bibliotheek.be website. + Created (initial version) on July 14, 2015 For usage of this module, see the examples folder and the docstrings @@ -168,12 +168,12 @@ def get_accounts(self) -> list[Account]: return accounts def get_all_info(self, all_as_dicts=False) -> dict: - """Returns all available information, for all accounts. + """Return all available information, for all accounts. Information is returned as a dict, with account ids as keys. Args: - all_as_dicts When True, do not return dataclass objects, but dicts + all_as_dicts: When True, do not return dataclass objects, but dicts instead. Raises: AuthenticationError diff --git a/src/mijnbib/parsers.py b/src/mijnbib/parsers.py index 203e4f7..0c8ecae 100644 --- a/src/mijnbib/parsers.py +++ b/src/mijnbib/parsers.py @@ -38,7 +38,7 @@ def __init__(self, html: str, base_url: str, account_id: str): self._acc_id = account_id def parse(self) -> list[Loan]: - """Return loans + """Return loans. >>> html_string=''' ...
@@ -138,7 +138,7 @@ def parse(self) -> list[Loan]: return loans def _get_loan_info_from_div(self, loan_div_html: str, branch: str) -> Loan: - """Return loan from html loan_div blob""" + """Return loan from html loan_div blob.""" loan_div = BeautifulSoup(loan_div_html, "html.parser") loan = {} @@ -229,7 +229,7 @@ def __init__(self, html: str, base_url: str): self._base_url = base_url def parse(self) -> list[Account]: - """Return list of accounts + """Return list of accounts. >>> html_string = ''' ... ... @@ -376,7 +376,7 @@ def parse(self) -> list[Account]: @staticmethod def _parse_item_count_from_li(acc_div, class_: str) -> int | None: - """Return None if no info found, otherwise return item count (potentially 0)""" + """Return None if no info found, otherwise return item count (potentially 0).""" item_count = None try: acc_a_text = acc_div.find("li", class_=class_).a.get_text().strip() @@ -396,7 +396,7 @@ def __init__(self, html: str): self._html = html def parse(self) -> list[Reservation]: - """Return list of holds + """Return list of holds. >>> html_string=''' ...
@@ -544,20 +544,20 @@ def __init__(self, html: str): self._html = html def parse(self) -> dict: - """For dict structure, see the called method""" + """For dict structure, see the called method.""" html_blob = self._extract_html_from_response_script_tag() return self._parse_extend_response_status_blob(html_blob) def _extract_html_from_response_script_tag(self): - """ + """Return html-encoded data from ajax encoded data. + The extending loan response contains the result in a ajax script thingy. This function extracts the part we are interested in and returns the decoded html. - See the tests for an example. """ def find_between(s: str, start: str, end: str): - """find_between("aabbcc", "aa", "cc") returns "bb" """ + # find_between("aabbcc", "aa", "cc") returns "bb" return s[s.find(start) + len(start) : s.rfind(end)] # find relevant snippet @@ -575,7 +575,7 @@ def find_between(s: str, start: str, end: str): @classmethod def _parse_extend_response_status_blob(cls, html_string: str) -> dict: - """Return details on loans that where extended succesfully + """Return details on loans that where extended succesfully. >>> html_string = ''' ...