Skip to content

Commit

Permalink
XmlAssembler unit test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteggink committed Sep 3, 2016
1 parent ca8c0f7 commit a61a6d2
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 11 deletions.
2 changes: 1 addition & 1 deletion stetl/filters/xmlassembler.py
Expand Up @@ -50,7 +50,7 @@ def consume_element(self, packet):
# Always move the data (element) from packet
element = packet.consume()

if element:
if element is not None:
self.total_element_count += 1
self.element_arr.append(element)

Expand Down
271 changes: 271 additions & 0 deletions tests/data/data_xmlassembler.gml
@@ -0,0 +1,271 @@
<?xml version="1.0" encoding="UTF-8"?>
<top10nl:FeatureCollectionT10NL xmlns:top10nl="http://register.geostandaarden.nl/gmlapplicatieschema/top10nl/1.2.0" xmlns:brt="http://register.geostandaarden.nl/gmlapplicatieschema/brt-algemeen/1.2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://register.geostandaarden.nl/gmlapplicatieschema/top10nl/1.2.0 top10nl.xsd" gml:id="NL.TOP10NL_FC1">
<!--Dit GML-bestand is gegenereerd met make-gml.xsl-->
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101010">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101010</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>arboretum</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied arboretum</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied arboretum</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:puntGeometrie>
<gml:Point gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:pos>101014.5 400104.5</gml:pos>
</gml:Point>
</brt:puntGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101011">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101011</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>arboretum</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied arboretum</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied arboretum</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:vlakGeometrie>
<gml:Polygon gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101010 400110 101019 400110 101019 400119 101010 400119 101010 400110</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</brt:vlakGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101012">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101012</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>arboretum</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied arboretum</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied arboretum</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:vlakGeometrie>
<gml:Polygon gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101010 400120 101019 400120 101019 400129 101010 400129 101010 400120</gml:posList>
</gml:LinearRing>
</gml:exterior>
<gml:interior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101013 400123 101013 400126 101016 400126 101016 400123 101013 400123</gml:posList>
</gml:LinearRing>
</gml:interior>
</gml:Polygon>
</brt:vlakGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101013">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101013</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>arboretum</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied arboretum</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied arboretum</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:multivlakGeometrie>
<gml:MultiSurface gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:surfaceMember>
<gml:Polygon gml:id="x">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101010 400130 101019 400130 101019 400134 101010 400134 101010 400130</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
<gml:surfaceMember>
<gml:Polygon gml:id="x">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101010 400135 101019 400135 101019 400139 101010 400139 101010 400135</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
</gml:MultiSurface>
</brt:multivlakGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101020">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101020</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>attractiepark</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied attractiepark</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied attractiepark</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:puntGeometrie>
<gml:Point gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:pos>101024.5 400104.5</gml:pos>
</gml:Point>
</brt:puntGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101021">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101021</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>attractiepark</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied attractiepark</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied attractiepark</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:vlakGeometrie>
<gml:Polygon gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101020 400110 101029 400110 101029 400119 101020 400119 101020 400110</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</brt:vlakGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
<top10nl:FeatureMember>
<top10nl:FunctioneelGebied gml:id="nl.top10nl.101022">
<top10nl:identificatie>
<brt:NEN3610ID>
<brt:namespace>NL.TOP10NL</brt:namespace>
<brt:lokaalID>101022</brt:lokaalID>
</brt:NEN3610ID>
</top10nl:identificatie>
<top10nl:brontype>Luchtfoto</top10nl:brontype>
<top10nl:bronactualiteit>2015-01-01</top10nl:bronactualiteit>
<top10nl:bronbeschrijving>Een orthogerectificeerde fotografische opname van een deel van het aardoppervlak. Gemaakt vanuit een vliegtuig.</top10nl:bronbeschrijving>
<top10nl:bronnauwkeurigheid>0.4</top10nl:bronnauwkeurigheid>
<top10nl:objectBeginTijd>2015-08-15</top10nl:objectBeginTijd>
<top10nl:tijdstipRegistratie>2015-08-15</top10nl:tijdstipRegistratie>
<top10nl:tdnCode>999</top10nl:tdnCode>
<top10nl:visualisatieCode>19160</top10nl:visualisatieCode>
<top10nl:mutatieType>TEST</top10nl:mutatieType>
<top10nl:typeFunctioneelGebied>attractiepark</top10nl:typeFunctioneelGebied>
<!--Het optionele attribuut soortnaam wordt overgeslagen-->
<top10nl:naamNL>Test typeFunctioneelGebied attractiepark</top10nl:naamNL>
<top10nl:naamFries>Test typeFunctioneelGebied attractiepark</top10nl:naamFries>
<top10nl:geometrie>
<brt:BRTVlakMultivlakOfPunt>
<brt:vlakGeometrie>
<gml:Polygon gml:id="x" srsName="urn:ogc:def:crs:EPSG::28992">
<gml:exterior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101020 400120 101029 400120 101029 400129 101020 400129 101020 400120</gml:posList>
</gml:LinearRing>
</gml:exterior>
<gml:interior>
<gml:LinearRing>
<gml:posList srsDimension="2" count="5">101023 400123 101023 400126 101026 400126 101026 400123 101023 400123</gml:posList>
</gml:LinearRing>
</gml:interior>
</gml:Polygon>
</brt:vlakGeometrie>
</brt:BRTVlakMultivlakOfPunt>
</top10nl:geometrie>
</top10nl:FunctioneelGebied>
</top10nl:FeatureMember>
</top10nl:FeatureCollectionT10NL>
2 changes: 1 addition & 1 deletion tests/filters/configs/xmlassembler.cfg
Expand Up @@ -16,7 +16,7 @@ element_tags = FeatureMember
[parse_xml_file_input]
class = inputs.fileinput.XmlElementStreamerFileInput
element_tags = FeatureMember
file_path = tests/data/dummy.gml
file_path = tests/data/data_xmlassembler.gml

# Assembles etree docs gml:featureMember elements, each with "max_elements" elements
[xml_assembler]
Expand Down
17 changes: 8 additions & 9 deletions tests/filters/test_xml_assembler.py
@@ -1,6 +1,4 @@
import os
#import re
import sys

from stetl.etl import ETL
from stetl.filters.xmlassembler import XmlAssembler
Expand Down Expand Up @@ -40,27 +38,28 @@ def test_execute(self):
# most Packets are empty, but we need to find 2 filled with etree docs
doc_packet_list = []
for packet in packet_list:
if packet.data:
if packet.data is not None:
doc_packet_list.append(packet)

# Assertion: we need to see 2 documents
self.assertEqual(len(doc_packet_list), 2)
self.assertEqual(len(doc_packet_list), 4)
namespaces={'gml': 'http://www.opengis.net/gml/3.2', 'top10nl': 'http://register.geostandaarden.nl/gmlapplicatieschema/top10nl/1.2.0'}

# Assertion: first doc has two FeatureMember elements with proper Namespaces
xml_doc1 = doc_packet_list[0].data
feature_elms = xml_doc1.xpath('/gml:FeatureCollectionT10NL/top10nl:FeatureMember', namespaces=namespaces)
self.assertEqual(len(feature_elms), 2)

# Assertion: second doc has one FeatureMember with proper Namespaces
xml_doc2 = doc_packet_list[1].data
# Assertion: last doc has one FeatureMember with proper Namespaces
last = len(doc_packet_list) - 1
xml_doc2 = doc_packet_list[last].data
feature_elms = xml_doc2.xpath('/gml:FeatureCollectionT10NL/top10nl:FeatureMember', namespaces=namespaces)
self.assertEqual(len(feature_elms), 1)

# Assertion: first doc has end_of_doc but not end_of_stream set
self.assertTrue(doc_packet_list[0].end_of_doc, msg='doc1: end_of_doc if False')
self.assertFalse(doc_packet_list[0].end_of_stream, msg='doc1: end_of_stream is True')

# Assertion: second doc has end_of_doc and end_of_stream set
self.assertTrue(doc_packet_list[1].end_of_doc, msg='doc2: end_of_doc if False')
self.assertTrue(doc_packet_list[1].end_of_stream, msg='doc2: end_of_stream if False')
# Assertion: last doc has end_of_doc and end_of_stream set
self.assertTrue(doc_packet_list[last].end_of_doc, msg='doc2: end_of_doc if False')
self.assertTrue(doc_packet_list[last].end_of_stream, msg='doc2: end_of_stream if False')

0 comments on commit a61a6d2

Please sign in to comment.