diff --git a/docs/source/conf.py b/docs/source/conf.py index 99dc446..382cc59 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -5,21 +5,15 @@ # serve to show the default. import sys -import os +from pathlib import Path + +from overpy import __about__ as overpy_about # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) -sys.path.insert( - 0, - os.path.abspath( - os.path.join( - os.path.dirname(__file__), - '../../' - ) - ) -) +sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent)) # -- General configuration ------------------------------------------------ @@ -57,7 +51,6 @@ # built documents. # # The short X.Y version. -from overpy import __about__ as overpy_about version = overpy_about.__version__ # The full version, including alpha/beta/rc tags. release = overpy_about.__version__ diff --git a/overpy/__init__.py b/overpy/__init__.py index 4909f67..a041e04 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -1,6 +1,8 @@ from collections import OrderedDict from datetime import datetime from decimal import Decimal +from urllib.request import urlopen +from urllib.error import HTTPError from xml.sax import handler, make_parser import json import re @@ -25,9 +27,6 @@ "visible": lambda v: v.lower() == "true" } -from urllib.request import urlopen -from urllib.error import HTTPError - def is_valid_type(element, cls): """ @@ -86,7 +85,8 @@ def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX, ma self.xml_parser = xml_parser - def _handle_remark_msg(self, msg): + @staticmethod + def _handle_remark_msg(msg): """ Try to parse the message provided with the remark tag or element. @@ -628,7 +628,7 @@ def get_center_from_json(cls, data): raise ValueError("Unable to get lat or lon of way center.") center_lat = Decimal(center_lat) center_lon = Decimal(center_lon) - return (center_lat, center_lon) + return center_lat, center_lon @classmethod def get_center_from_xml_dom(cls, sub_child): diff --git a/setup.py b/setup.py index d1b0014..b74ee3c 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,15 @@ #!/usr/bin/env python import os import sys +from pathlib import Path from setuptools import setup, find_packages -base_dir = os.path.dirname(__file__) +HERE = Path(__file__).resolve().parent about = {} -with open(os.path.join(base_dir, "overpy", "__about__.py")) as f: - exec(f.read(), about) +exec((HERE / "overpy" / "__about__.py").read_text(), about) -filename_readme = os.path.join(base_dir, "README.rst") -if sys.version_info[0] == 2: - import io - fp = open(filename_readme, encoding="utf-8") -else: - fp = open(filename_readme, encoding="utf-8") -long_description = fp.read() +long_description = (HERE / "README.rst").read_text() setup( name=about["__title__"], diff --git a/tests/__init__.py b/tests/__init__.py index 8cb357d..d59ab53 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,6 @@ -import os import sys import threading +from pathlib import Path from threading import Lock from socketserver import BaseRequestHandler, TCPServer, ThreadingMixIn @@ -21,13 +21,12 @@ def handle(self): self.request.send(data) @staticmethod - def get_response(self): + def get_response(): yield b"" def read_file(filename, mode="r"): - filename = os.path.join(os.path.dirname(__file__), filename) - return open(filename, mode).read() + return (Path(__file__).resolve().parent / filename).open(mode).read() def new_server_thread(handle_cls, port=None): diff --git a/tests/base_class.py b/tests/base_class.py index 03f6b59..be89a1a 100644 --- a/tests/base_class.py +++ b/tests/base_class.py @@ -10,7 +10,8 @@ class BaseTestAreas: - def _test_area01(self, result): + @staticmethod + def _test_area01(result): assert len(result.areas) == 4 assert len(result.nodes) == 0 assert len(result.relations) == 0 @@ -77,7 +78,8 @@ def _test_area01(self, result): class BaseTestNodes: - def _test_node01(self, result): + @staticmethod + def _test_node01(result): assert len(result.nodes) == 3 assert len(result.relations) == 0 assert len(result.ways) == 0 @@ -151,7 +153,8 @@ def _test_node01(self, result): class BaseTestRelation: - def _test_relation01(self, result): + @staticmethod + def _test_relation01(result): assert len(result.nodes) == 0 assert len(result.relations) == 1 assert len(result.ways) == 0 @@ -187,7 +190,8 @@ def _test_relation01(self, result): assert isinstance(relation.members[3], overpy.RelationNode) assert isinstance(relation.members[4], overpy.RelationWay) - def _test_relation02(self, result): + @staticmethod + def _test_relation02(result): assert len(result.nodes) == 3 assert len(result.relations) == 1 assert len(result.ways) == 1 @@ -240,7 +244,8 @@ def _test_relation02(self, result): assert way.id == 317146078 assert member.ref == way.id - def _test_relation03(self, result): + @staticmethod + def _test_relation03(result): assert len(result.nodes) == 0 assert len(result.relations) == 1 assert len(result.ways) == 0 @@ -259,7 +264,8 @@ def _test_relation03(self, result): assert relation.center_lat == Decimal("50.8176646") assert relation.center_lon == Decimal("7.0208539") - def _test_relation04(self, result): + @staticmethod + def _test_relation04(result): assert len(result.nodes) == 0 assert len(result.relations) == 1 assert len(result.ways) == 0 @@ -289,7 +295,8 @@ def _test_relation04(self, result): class BaseTestWay: - def _test_way01(self, result): + @staticmethod + def _test_way01(result): assert len(result.nodes) == 0 assert len(result.relations) == 0 assert len(result.ways) == 2 @@ -345,7 +352,8 @@ def _test_way01(self, result): assert way_ids[0] == 317146077 assert way_ids[1] == 317146078 - def _test_way02(self, result): + @staticmethod + def _test_way02(result): assert len(result.nodes) == 6 assert len(result.relations) == 0 assert len(result.ways) == 1 @@ -405,7 +413,8 @@ def _test_way02(self, result): assert len(way_ids) == 1 assert way_ids[0] == 317146077 - def _test_way03(self, result): + @staticmethod + def _test_way03(result): assert len(result.nodes) == 4 assert len(result.relations) == 0 assert len(result.ways) == 1 diff --git a/tests/test_exception.py b/tests/test_exception.py index afe5682..158588d 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -5,7 +5,7 @@ class TestExceptions: def test_element_data_wrong_type(self): e = overpy.exception.ElementDataWrongType("from1") assert e.type_expected == "from1" - assert e.type_provided == None + assert e.type_provided is None assert isinstance(str(e), str) e = overpy.exception.ElementDataWrongType("from2", "to2") @@ -28,7 +28,7 @@ def test_overpass_bad_request(self): def test_overpass_unknown_content_type(self): e = overpy.exception.OverpassUnknownContentType(None) - assert e.content_type == None + assert e.content_type is None assert str(e).startswith("No content") e = overpy.exception.OverpassUnknownContentType("content") diff --git a/tests/test_xml.py b/tests/test_xml.py index c199e68..7c3c9db 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -106,7 +106,8 @@ def test_way04(self): class TestDataError: - def _get_element_wrong_type(self): + @staticmethod + def _get_element_wrong_type(): data = "" import xml.etree.ElementTree as ET return ET.fromstring(data)