def test_parse_xml(self): """Test parsing the xml works correctly.""" xml_path = test_data_path("collections", "test_collection", "symbol", "various_symbols.xml") extractor = SymbolXMLExtractor(xml_path) self.assertTrue(extractor.parse_xml()) # There are 9 symbols and 3 colorramps there expected_symbols = { "fill_raster": QgsFillSymbol, "fill_svg": QgsFillSymbol, "fill_svg_line": QgsFillSymbol, "line_arrow": QgsLineSymbol, "line_svg_marker": QgsLineSymbol, "marker_ellipse": QgsMarkerSymbol, "marker_font": QgsMarkerSymbol, "marker_simple": QgsMarkerSymbol, "marker_svg": QgsMarkerSymbol, } self.assertEqual(len(extractor.symbols), len(expected_symbols)) for symbol in extractor.symbols: self.assertTrue( isinstance(symbol["symbol"], expected_symbols[symbol["name"]])) expected_colorramps = { "cr_colorbrewer": QgsColorBrewerColorRamp, "cr_gradient": QgsGradientColorRamp, "cr_random": random_color_ramp, # QGIS 2.x is QgsRandomColorRamp QGIS 3.x is QgsLimitedRandomColorRamp } self.assertEqual(len(extractor.colorramps), len(expected_colorramps)) for colorramp in extractor.colorramps: self.assertTrue( isinstance(colorramp["colorramp"], expected_colorramps[colorramp["name"]]))
def test_parse_xml(self): """Test parsing the xml works correctly.""" xml_path = test_data_path('collections', 'test_collection', 'symbol', 'various_symbols.xml') extractor = SymbolXMLExtractor(xml_path) self.assertTrue(extractor.parse_xml()) # There are 9 symbols and 3 colorramps there expected_symbols = { 'fill_raster': QgsFillSymbol, 'fill_svg': QgsFillSymbol, 'fill_svg_line': QgsFillSymbol, 'line_arrow': QgsLineSymbol, 'line_svg_marker': QgsLineSymbol, 'marker_ellipse': QgsMarkerSymbol, 'marker_font': QgsMarkerSymbol, 'marker_simple': QgsMarkerSymbol, 'marker_svg': QgsMarkerSymbol } self.assertEqual(len(extractor.symbols), len(expected_symbols)) for symbol in extractor.symbols: self.assertTrue( isinstance(symbol['symbol'], expected_symbols[symbol['name']])) expected_colorramps = { 'cr_colorbrewer': QgsColorBrewerColorRamp, 'cr_gradient': QgsGradientColorRamp, 'cr_random': random_color_ramp # QGIS 2.x is QgsRandomColorRamp QGIS 3.x is QgsLimitedRandomColorRamp } self.assertEqual(len(extractor.colorramps), len(expected_colorramps)) for colorramp in extractor.colorramps: self.assertTrue( isinstance(colorramp['colorramp'], expected_colorramps[colorramp['name']]))
def test_parse_xml(self): """Test parsing the xml works correctly.""" xml_path = test_data_path( 'collections', 'test_collection', 'symbol', 'various_symbols.xml') extractor = SymbolXMLExtractor(xml_path) self.assertTrue(extractor.parse_xml()) # There are 9 symbols and 3 colorramps there expected_symbols = { 'fill_raster': QgsFillSymbol, 'fill_svg': QgsFillSymbol, 'fill_svg_line': QgsFillSymbol, 'line_arrow': QgsLineSymbol, 'line_svg_marker': QgsLineSymbol, 'marker_ellipse': QgsMarkerSymbol, 'marker_font': QgsMarkerSymbol, 'marker_simple': QgsMarkerSymbol, 'marker_svg': QgsMarkerSymbol } self.assertEqual(len(extractor.symbols), len(expected_symbols)) for symbol in extractor.symbols: self.assertTrue( isinstance(symbol['symbol'], expected_symbols[symbol['name']]) ) expected_colorramps = { 'cr_colorbrewer': QgsColorBrewerColorRamp, 'cr_gradient': QgsGradientColorRamp, 'cr_random': random_color_ramp # QGIS 2.x is QgsRandomColorRamp QGIS 3.x is QgsLimitedRandomColorRamp } self.assertEqual(len(extractor.colorramps), len(expected_colorramps)) for colorramp in extractor.colorramps: self.assertTrue( isinstance(colorramp['colorramp'], expected_colorramps[colorramp['name']]) )
def test_fetch_metadata(self): """Test fetch_metadata function.""" # TC1: Normal successful testcase self.assertIsNone(self.fs_handler.metadata) status, _ = self.fs_handler.fetch_metadata() self.assertTrue(status) self.assertIsNotNone(self.fs_handler.metadata) metadata_path = test_data_path('metadata.ini') with open(metadata_path, 'r') as metadata_file: expected_content = metadata_file.read() self.assertEqual(self.fs_handler.metadata, expected_content)
def test_resolve_path(self): """Test resolving the path works correctly.""" collection_path = test_data_path('collections', 'test_collection') search_paths = [] # Test case 1: local path img_path = test_data_path( 'collections', 'test_collection', 'svg', 'blastoise.svg') fixed_path = resolve_path(img_path, collection_path, search_paths) self.assertEqual(img_path, fixed_path) # Test case 2: local url img_path = test_data_path( 'collections', 'test_collection', 'svg', 'blastoise.svg') img_url = QUrl.fromLocalFile(img_path) fixed_path = resolve_path( img_url.toString(), collection_path, search_paths) self.assertEqual(fixed_path, img_path) # Test case 3: http url img_path = 'http://qgis.org/test/image.svg' img_url = QUrl(img_path) fixed_path = resolve_path( img_url.toString(), collection_path, search_paths) self.assertEqual(fixed_path, img_path) # Test case 4: checking in the svg local collection path img_path = '/you/would/not/find/this/charizard.svg' fixed_path = resolve_path(img_path, collection_path, search_paths) expected_path = test_data_path( 'collections', 'test_collection', 'svg', 'charizard.svg') self.assertEqual(fixed_path, expected_path) # Test case 5: checking in the image local collection path img_path = '/you/would/not/find/this/pikachu.png' fixed_path = resolve_path(img_path, collection_path, search_paths) expected_path = test_data_path( 'collections', 'test_collection', 'image', 'pikachu.png') self.assertEqual(fixed_path, expected_path) # Test case 6: checking in the search paths search_paths = [ test_data_path( 'collections', 'test_collection', 'preview') ] img_path = 'prev_1.png' fixed_path = resolve_path(img_path, collection_path, search_paths) expected_path = test_data_path( 'collections', 'test_collection', 'preview', 'prev_1.png') self.assertEqual(fixed_path, expected_path) # Test case 7: not finding anywhere (return the original path) img_path = '/you/would/not/find/this/anywhere.png' fixed_path = resolve_path(img_path, collection_path, search_paths) self.assertEqual(fixed_path, img_path)
def test_resolve_path(self): """Test resolving the path works correctly.""" collection_path = test_data_path("collections", "test_collection") search_paths = [] # Test case 1: local path img_path = test_data_path( "collections", "test_collection", "svg", "blastoise.svg" ) fixed_path = resolve_path(img_path, collection_path, search_paths) self.assertEqual(img_path, fixed_path) # Test case 2: local url img_path = test_data_path( "collections", "test_collection", "svg", "blastoise.svg" ) img_url = QUrl.fromLocalFile(img_path) fixed_path = resolve_path(img_url.toString(), collection_path, search_paths) self.assertEqual(fixed_path, img_path) # Test case 3: http url img_path = "http://qgis.org/test/image.svg" img_url = QUrl(img_path) fixed_path = resolve_path(img_url.toString(), collection_path, search_paths) self.assertEqual(fixed_path, img_path) # Test case 4: checking in the svg local collection path img_path = "/you/would/not/find/this/charizard.svg" fixed_path = resolve_path(img_path, collection_path, search_paths) expected_path = test_data_path( "collections", "test_collection", "svg", "charizard.svg" ) self.assertEqual(fixed_path, expected_path) # Test case 5: checking in the image local collection path img_path = "/you/would/not/find/this/pikachu.png" fixed_path = resolve_path(img_path, collection_path, search_paths) expected_path = test_data_path( "collections", "test_collection", "image", "pikachu.png" ) self.assertEqual(fixed_path, expected_path) # Test case 6: checking in the search paths search_paths = [test_data_path("collections", "test_collection", "preview")] img_path = "prev_1.png" fixed_path = resolve_path(img_path, collection_path, search_paths) expected_path = test_data_path( "collections", "test_collection", "preview", "prev_1.png" ) self.assertEqual(fixed_path, expected_path) # Test case 7: not finding anywhere (return the original path) img_path = "/you/would/not/find/this/anywhere.png" fixed_path = resolve_path(img_path, collection_path, search_paths) self.assertEqual(fixed_path, img_path)
def test_fix_xml_node(self): """Test if fixing xml node works.""" symbol_xml = """ <symbol alpha="1" clip_to_extent="1" type="fill" name="fill_raster"> <layer pass="******" class="RasterFill" locked="0"> <prop k="alpha" v="1"/> <prop k="angle" v="0"/> <prop k="coordinate_mode" v="0"/> <prop k="imageFile" v="/you/will/not/find/pikachu.png"/> <prop k="offset" v="0,0"/> <prop k="offset_map_unit_scale" v="0,0,0,0,0,0"/> <prop k="offset_unit" v="MM"/> <prop k="width" v="0"/> <prop k="width_map_unit_scale" v="0,0,0,0,0,0"/> <prop k="width_unit" v="Pixel"/> </layer> </symbol> """ collection_path = test_data_path("collections", "test_collection") fixed_xml = self._to_str(fix_xml_node(symbol_xml, collection_path, [])) expected_xml = """<symbol alpha="1" clip_to_extent="1" name="fill_raster" type="fill"> <layer class="RasterFill" locked="0" pass="******"> <prop k="alpha" v="1" /> <prop k="angle" v="0" /> <prop k="coordinate_mode" v="0" /> <prop k="imageFile" v="{0}/collections/test_collection/image/pikachu.png" /> <prop k="offset" v="0,0" /> <prop k="offset_map_unit_scale" v="0,0,0,0,0,0" /> <prop k="offset_unit" v="MM" /> <prop k="width" v="0" /> <prop k="width_map_unit_scale" v="0,0,0,0,0,0" /> <prop k="width_unit" v="Pixel" /> </layer> </symbol>""".format( test_data_path() ) self.assertEqual(fixed_xml, expected_xml)
def test_fix_xml_node(self): """Test if fixing xml node works.""" symbol_xml = """ <symbol alpha="1" clip_to_extent="1" type="fill" name="fill_raster"> <layer pass="******" class="RasterFill" locked="0"> <prop k="alpha" v="1"/> <prop k="angle" v="0"/> <prop k="coordinate_mode" v="0"/> <prop k="imageFile" v="/you/will/not/find/pikachu.png"/> <prop k="offset" v="0,0"/> <prop k="offset_map_unit_scale" v="0,0,0,0,0,0"/> <prop k="offset_unit" v="MM"/> <prop k="width" v="0"/> <prop k="width_map_unit_scale" v="0,0,0,0,0,0"/> <prop k="width_unit" v="Pixel"/> </layer> </symbol> """ collection_path = test_data_path('collections', 'test_collection') fixed_xml = self._to_str(fix_xml_node(symbol_xml, collection_path, [])) expected_xml = """<symbol alpha="1" clip_to_extent="1" name="fill_raster" type="fill"> <layer class="RasterFill" locked="0" pass="******"> <prop k="alpha" v="1" /> <prop k="angle" v="0" /> <prop k="coordinate_mode" v="0" /> <prop k="imageFile" v="{0}/collections/test_collection/image/pikachu.png" /> <prop k="offset" v="0,0" /> <prop k="offset_map_unit_scale" v="0,0,0,0,0,0" /> <prop k="offset_unit" v="MM" /> <prop k="width" v="0" /> <prop k="width_map_unit_scale" v="0,0,0,0,0,0" /> <prop k="width_unit" v="Pixel" /> </layer> </symbol>""".format(test_data_path()) self.assertEqual(fixed_xml, expected_xml)