From 66f8bdb45ec6973efca3c712678a88a4ef020a2e Mon Sep 17 00:00:00 2001 From: Henry Walshaw Date: Mon, 29 Jul 2019 10:24:02 +1000 Subject: [PATCH] Fix errors from make test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One Python 2.7 error in the test (didn’t work for points) Also fixed all the formatting errors raised by flake8 --- feedgen/ext/geo_entry.py | 43 ++++++++++++++++++++----------- tests/test_extensions/test_geo.py | 35 ++++++++++++++----------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/feedgen/ext/geo_entry.py b/feedgen/ext/geo_entry.py index 2fcc409..2ad6611 100644 --- a/feedgen/ext/geo_entry.py +++ b/feedgen/ext/geo_entry.py @@ -30,8 +30,9 @@ class GeoRSSPolygonInteriorWarning(Warning): def __str__(self): return '{:d} interiors of polygon ignored'.format( - len(self.geom.__geo_interface__['coordinates']) - 1 # ignore exterior in count - ) + len(self.geom.__geo_interface__['coordinates']) - 1 + ) # ignore exterior in count + class GeoRSSGeometryError(ValueError): """ @@ -39,7 +40,6 @@ class GeoRSSGeometryError(ValueError): Only some geometries are supported in Simple GeoRSS, so if not raise an error. Offending geometry is stored on the ``geom`` attribute. - """ def __init__(self, geom, *args, **kwargs): @@ -47,7 +47,8 @@ class GeoRSSGeometryError(ValueError): super(GeoRSSGeometryError, self).__init__(*args, **kwargs) def __str__(self): - return "Geometry of type '{}' not in Point, Linestring or Polygon".format( + msg = "Geometry of type '{}' not in Point, Linestring or Polygon" + return msg.format( self.geom.__geo_interface__['type'] ) @@ -101,11 +102,17 @@ class GeoEntryExtension(BaseEntryExtension): box.text = self.__box if self.__featuretypetag: - featuretypetag = etree.SubElement(entry, '{%s}featuretypetag' % GEO_NS) + featuretypetag = etree.SubElement( + entry, + '{%s}featuretypetag' % GEO_NS + ) featuretypetag.text = self.__featuretypetag if self.__relationshiptag: - relationshiptag = etree.SubElement(entry, '{%s}relationshiptag' % GEO_NS) + relationshiptag = etree.SubElement( + entry, + '{%s}relationshiptag' % GEO_NS + ) relationshiptag.text = self.__relationshiptag if self.__featurename: @@ -147,7 +154,8 @@ class GeoEntryExtension(BaseEntryExtension): def line(self, line=None): '''Get or set the georss:line of the entry - :param point: The GeoRSS formatted line (i.e. "45.256 -110.45 46.46 -109.48 43.84 -109.86") + :param point: The GeoRSS formatted line (i.e. "45.256 -110.45 46.46 + -109.48 43.84 -109.86") :return: The current georss:line of the entry ''' if line is not None: @@ -158,7 +166,8 @@ class GeoEntryExtension(BaseEntryExtension): def polygon(self, polygon=None): '''Get or set the georss:polygon of the entry - :param polygon: The GeoRSS formatted polygon (i.e. "45.256 -110.45 46.46 -109.48 43.84 -109.86 45.256 -110.45") + :param polygon: The GeoRSS formatted polygon (i.e. "45.256 -110.45 + 46.46 -109.48 43.84 -109.86 45.256 -110.45") :return: The current georss:polygon of the entry ''' if polygon is not None: @@ -170,7 +179,8 @@ class GeoEntryExtension(BaseEntryExtension): ''' Get or set the georss:box of the entry - :param box: The GeoRSS formatted box (i.e. "42.943 -71.032 43.039 -69.856") + :param box: The GeoRSS formatted box (i.e. "42.943 -71.032 43.039 + -69.856") :return: The current georss:box of the entry ''' if box is not None: @@ -194,7 +204,8 @@ class GeoEntryExtension(BaseEntryExtension): ''' Get or set the georss:relationshiptag of the entry - :param relationshiptag: The GeoRSS relationshiptag (e.g. "is-centred-at") + :param relationshiptag: The GeoRSS relationshiptag (e.g. + "is-centred-at") :return: the current georss:relationshiptag ''' if relationshiptag is not None: @@ -256,7 +267,9 @@ class GeoEntryExtension(BaseEntryExtension): ''' if radius is not None: if not isinstance(radius, numbers.Number): - raise ValueError("radius tag must be numeric: {}".format(radius)) + raise ValueError( + "radius tag must be numeric: {}".format(radius) + ) self.__radius = radius @@ -268,13 +281,13 @@ class GeoEntryExtension(BaseEntryExtension): ``__geo_interface__`` property (see the `geo_interface specification by Sean Gillies`_geointerface ) - Note only a subset of GeoJSON (see `geojson.org`_geojson ) can be easily - converted to GeoRSS: + Note only a subset of GeoJSON (see `geojson.org`_geojson ) can be + easily converted to GeoRSS: - Point - LineString - - Polygon (if there are holes / donuts in the polygons a warning will be - generaated + - Polygon (if there are holes / donuts in the polygons a warning will + be generaated Other GeoJson types will raise a ``ValueError``. diff --git a/tests/test_extensions/test_geo.py b/tests/test_extensions/test_geo.py index 01990a6..6dd401b 100644 --- a/tests/test_extensions/test_geo.py +++ b/tests/test_extensions/test_geo.py @@ -5,7 +5,7 @@ import warnings from lxml import etree from feedgen.feed import FeedGenerator -from feedgen.ext.geo_entry import GeoRSSPolygonInteriorWarning, GeoRSSGeometryError +from feedgen.ext.geo_entry import GeoRSSPolygonInteriorWarning, GeoRSSGeometryError # noqa: E501 class Geom(object): @@ -78,19 +78,22 @@ class TestExtensionGeo(unittest.TestCase): def setUpClass(cls): cls.point = Geom('Point', [-71.05, 42.36]) cls.line = Geom('LineString', [[-71.05, 42.36], [-71.15, 42.46]]) - cls.polygon = Geom('Polygon', [[[-71.05, 42.36], [-71.15, 42.46], [-71.15, 42.36]]]) + cls.polygon = Geom( + 'Polygon', + [[[-71.05, 42.36], [-71.15, 42.46], [-71.15, 42.36]]] + ) cls.box = Geom('Box', [[-71.05, 42.36], [-71.15, 42.46]]) cls.polygon_with_interior = Geom( 'Polygon', [ - [ # exterior + [ # exterior [0, 0], [0, 1], [1, 1], [1, 0], [0, 0] ], - [ # interior + [ # interior [0.25, 0.25], [0.25, 0.75], [0.75, 0.75], @@ -131,8 +134,10 @@ class TestExtensionGeo(unittest.TestCase): # Check that we have the item in the resulting XML ns = {'georss': 'http://www.georss.org/georss'} root = etree.fromstring(self.fg.rss_str()) - line = root.xpath('/rss/channel/item/georss:line/text()', - namespaces=ns) + line = root.xpath( + '/rss/channel/item/georss:line/text()', + namespaces=ns + ) self.assertEqual(line, [str(self.line)]) def test_polygon(self): @@ -145,8 +150,10 @@ class TestExtensionGeo(unittest.TestCase): # Check that we have the item in the resulting XML ns = {'georss': 'http://www.georss.org/georss'} root = etree.fromstring(self.fg.rss_str()) - poly = root.xpath('/rss/channel/item/georss:polygon/text()', - namespaces=ns) + poly = root.xpath( + '/rss/channel/item/georss:polygon/text()', + namespaces=ns + ) self.assertEqual(poly, [str(self.polygon)]) def test_box(self): @@ -159,8 +166,10 @@ class TestExtensionGeo(unittest.TestCase): # Check that we have the item in the resulting XML ns = {'georss': 'http://www.georss.org/georss'} root = etree.fromstring(self.fg.rss_str()) - box = root.xpath('/rss/channel/item/georss:box/text()', - namespaces=ns) + box = root.xpath( + '/rss/channel/item/georss:box/text()', + namespaces=ns + ) self.assertEqual(box, [str(self.box)]) def test_featuretypetag(self): @@ -307,11 +316,9 @@ class TestExtensionGeo(unittest.TestCase): except AttributeError: # was assertItemsEqual in Python 2.7 self.assertItemsEqual( coords, - list(chain.from_iterable(self.point.coords)) + self.point.coords ) - - def test_geom_from_geointerface_line(self): fe = self.fg.add_item() fe.title('y') @@ -339,7 +346,6 @@ class TestExtensionGeo(unittest.TestCase): list(chain.from_iterable(self.line.coords)) ) - def test_geom_from_geointerface_poly(self): fe = self.fg.add_item() fe.title('y') @@ -381,7 +387,6 @@ class TestExtensionGeo(unittest.TestCase): with self.assertRaises(AttributeError): fe.geo.geom_from_geo_interface(str(self.box)) - def test_geom_from_geointerface_warn_poly_interior(self): """ Test complex polygons warn as expected. Taken from