def test_recipe_atlas_constructor(self): cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json') # 1) atlas matches other sections 'fixture_cookbook_good_with_atlas.json' cmf.map_definitions = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_cookbook_good_with_atlas.json') test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) MapCookbook(cmf, test_lp, verify_on_creation=True) self.assertTrue(True) # 2) mismatch map_frame name 'fixture_cookbook_atlas_mismatch_map_frame.json' # 3) mismatch layer name (but present in other map frame) 'fixture_cookbook_atlas_mismatch_layer1.json' # 4) mismatch layer name, not present elsewhere in the recipe. 'fixture_cookbook_atlas_mismatch_layer2.json' # 5) mismatch column_names test_cb_names = ('fixture_cookbook_atlas_mismatch_map_frame.json', 'fixture_cookbook_atlas_mismatch_layer1.json', 'fixture_cookbook_atlas_mismatch_layer2.json', 'fixture_cookbook_atlas_mismatch_column_name.json') for test_cb in test_cb_names: cmf.map_definitions = os.path.join(self.parent_dir, 'tests', 'testfiles', 'cookbooks', test_cb) test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) with self.assertRaises(ValueError): MapCookbook(cmf, test_lp, verify_on_creation=True)
def test_check_for_dup_text_elements(self): cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json') # 1) Pass with "good" text elements in just one map_frame cmf.map_definitions = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_cookbook_good_with_atlas.json') test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) MapCookbook(cmf, test_lp, verify_on_creation=True) self.assertTrue(True) # 2) Fail with duplicate text elements in multiple map_frames cmf.map_definitions = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_cookbook_with_dup_text_elements.json') test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) with self.assertRaises(ValueError) as ve: MapCookbook(cmf, test_lp, verify_on_creation=True) fail_msg = 'More than one "map_frame" is linked to the Scale text element "scale"' if six.PY2: self.assertRegexpMatches(str(ve.exception), fail_msg) else: self.assertRegex(str(ve.exception), fail_msg)
def test_check_for_dup_layers_and_mapframs(self): cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json') # Fail with multiple layer with the same name in the same mapframe. test_cookbooks = (('fixture_cookbook_with_dup_layers.json', 'mainmap_tran_por_pt_s0_allmaps'), ('fixture_cookbook_with_dup_mapframes.json', 'Main map')) for cb_filename, fail_msg in test_cookbooks: cmf.map_definitions = os.path.join(self.parent_dir, 'tests', 'testfiles', 'cookbooks', cb_filename) test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) with self.assertRaises(ValueError) as ve: MapCookbook(cmf, test_lp, verify_on_creation=True) if six.PY2: self.assertRegexpMatches(str(ve.exception), fail_msg) else: self.assertRegex(str(ve.exception), fail_msg)
def test_zero_length_file_extention(self): test_cmf = CrashMoveFolder(self.path_to_valid_cmf_des) test_lp1 = LayerProperties(test_cmf, '', verify_on_creation=False) self.assertIsInstance(test_lp1, LayerProperties) layer_rendering_test_root = os.path.join(self.parent_dir, 'tests', 'testfiles', 'test_layer_rendering') test_cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_layer_properties_four_layers.json') test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_exact_match') test_lp2 = LayerProperties(test_cmf, '', verify_on_creation=True) self.assertIsInstance(test_lp2, LayerProperties)
def test_get_aspect_ratios_of_templates(self, mock_ListDataFrames, mock_MapDocument): mock_MapDocument.return_value = None df_lists = [[self.df1], [self.df2], [self.df3], [self.df4], [self.df5], [self.df6]] mock_ListDataFrames.side_effect = df_lists tmpl_paths = repeat('/the/path', len(df_lists)) tmpl_paths = ['/the/path{}'.format(n) for n in range(1, 7)] test_lp = LayerProperties(self.cmf, '.lyr') test_recipe = MapRecipe(fixtures.fixture_recipe_minimal, test_lp) expected_result = [ ('/the/path1', float(self.df1.elementWidth) / self.df1.elementHeight), ('/the/path2', float(self.df2.elementWidth) / self.df2.elementHeight), ('/the/path3', float(self.df3.elementWidth) / self.df3.elementHeight), ('/the/path4', float(self.df4.elementWidth) / self.df4.elementHeight), ('/the/path5', float(self.df5.elementWidth) / self.df5.elementHeight), ('/the/path6', float(self.df6.elementWidth) / self.df6.elementHeight) ] actual_result = self.arcmap_runner.get_aspect_ratios_of_templates( tmpl_paths, test_recipe) self.assertEqual(actual_result, expected_result)
def setUp(self): self.parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) self.path_to_valid_cmf_des = os.path.join(self.parent_dir, 'example', 'cmf_description_flat_test.json') self.path_to_invalid_cmf_des = os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_cmf_description_one_file_and_one_dir_not_valid.json') self.cmf = CrashMoveFolder(self.path_to_valid_cmf_des, verify_on_creation=False) self.lyr_props = LayerProperties(self.cmf, '', verify_on_creation=False)
def setUp(self): self.parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) self.cmf_descriptor_path = os.path.join(self.parent_dir, 'example', 'cmf_description_flat_test.json') self.event_descriptor_path = os.path.join(self.parent_dir, 'example', 'event_description.json') self.recipe_file = os.path.join(self.parent_dir, 'example', 'example_single_map_recipe.json') self.non_existant_file = os.path.join(self.parent_dir, 'example', 'non-existant-file.json') self.cmf = CrashMoveFolder(self.cmf_descriptor_path, verify_on_creation=False) self.event = Event(self.event_descriptor_path) # self.cmf = CrashMoveFolder(self.cmf_descriptor_path) self.lyr_props = LayerProperties(self.cmf, '', verify_on_creation=False)
def test_different_cmf_args(self): # 1) test with valid cmf object test_cmf = CrashMoveFolder(self.path_to_valid_cmf_des) test_lp = LayerProperties(test_cmf, "test", verify_on_creation=False) self.assertIsInstance(test_lp, LayerProperties) # 2) test with valid cmf file test_lp = LayerProperties(self.path_to_valid_cmf_des, "test", verify_on_creation=False) self.assertIsInstance(test_lp, LayerProperties) # 3) test with invalid cmf object (eg and CrashMoveFolder object # where verify_paths() returns False) test_cmf = CrashMoveFolder(self.path_to_invalid_cmf_des, verify_on_creation=False) self.assertRaises(ValueError, LayerProperties, test_cmf, "test") # 4) test with invalid cmd file self.assertRaises(ValueError, LayerProperties, self.path_to_invalid_cmf_des, "test")
def check_lyr_props_vs_map_cookbook(self, **kwargs): try: cmf = CrashMoveFolder(self.cmf_desc_path) lyrs = LayerProperties(cmf, '', verify_on_creation=False) MapCookbook(cmf, lyrs, verify_on_creation=True) return ( 'No inconsistency detected between:\n' ' * the contents of the layer properties json file:\n\t{props}\n' ' * and the contents of the MapCookbook json:\n\t{cbook}\n'. format(props=cmf.layer_properties, cbook=cmf.map_definitions)) except ValueError: raise
def check_json_file_schemas(self, **kwargs): try: # JSON schema validation is implicit in the creation of these objects self.check_cmf_description() lp = LayerProperties(self.cmf, '', verify_on_creation=False) MapCookbook(self.cmf, lp, verify_on_creation=False) return ( 'No json validation problems were detected in the parsing of these two' ' files:\n"{}"\n"{}"'.format(lp.cmf.layer_properties, self.cmf.map_definitions)) except ValueError: raise
def check_lyr_props_vs_rendering_dir(self, **kwargs): cmf = CrashMoveFolder(self.cmf_desc_path) for lyr_exn in self.lyr_file_exn_list: try: LayerProperties(cmf, lyr_exn, verify_on_creation=True) return ( 'No inconsistency detected between:\n' ' * the contents of the layer properties json file:\n\t{props}\n' ' * and layer rendering dir:\n\t{render}\n'.format( props=cmf.layer_properties, render=cmf.layer_rendering)) except ValueError: raise
def test_different_cmf_args(self): # 1) test with valid CMF and LayerProperties objects test_cmf = CrashMoveFolder(self.path_to_valid_cmf_des) test_lp = LayerProperties(test_cmf, "test", verify_on_creation=False) test_mcb = MapCookbook(test_cmf, test_lp, verify_on_creation=False) self.assertIsInstance(test_mcb, MapCookbook) # 2) test with invalid cmf object (eg and CrashMoveFolder object # where verify_paths() returns False) test_cmf = CrashMoveFolder(self.path_to_invalid_cmf_des, verify_on_creation=False) self.assertRaises(ValueError, MapCookbook, test_cmf, test_lp)
def setUp(self): self.parent_dir = os.path.dirname( os.path.dirname(os.path.realpath(__file__))) self.dir_to_valid_cmf_des = os.path.join(self.parent_dir, 'example') self.path_to_valid_cmf_des = os.path.join( self.dir_to_valid_cmf_des, 'cmf_description_flat_test.json') self.path_to_event_des = os.path.join(self.dir_to_valid_cmf_des, 'event_description.json') self.cmf = CrashMoveFolder(self.path_to_valid_cmf_des) self.lyr_props = LayerProperties(self.cmf, '', verify_on_creation=False) self.dummy_runner = DummyRunner(Event(self.path_to_event_des))
def setUp(self): self.parent_dir = os.path.dirname( os.path.dirname(os.path.realpath(__file__))) self.path_to_valid_cmf_des = os.path.join( self.parent_dir, 'tests', 'test_data', 'fixture_cmf_description_flat_test.json') self.cmf = CrashMoveFolder(self.path_to_valid_cmf_des) self.event = Event( os.path.join(self.parent_dir, 'tests', 'test_data', 'event_description.json')) self.my_mxd_fname = os.path.join( self.parent_dir, 'tests', 'test_data', 'output_arcgis_10_6_reference_landscape_bottom.mxd') self.layer_props = LayerProperties(self.cmf, '.lyr') self.cookBook = MapCookbook(self.cmf, self.layer_props)
def test_layer_props_and_cookbook_mismatch(self): cmf = CrashMoveFolder(self.path_to_valid_cmf_des) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_layer_properties_four_layers.json') cmf.map_definitions = os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_cookbook_1map_4layers.json') test_lp = LayerProperties(cmf, "test", verify_on_creation=False) # 1) map_cb and lp match test_mcb = MapCookbook(cmf, test_lp, verify_on_creation=True) self.assertIsInstance(test_mcb, MapCookbook) # 2) layer in map_cb but not in lp # 3) layer in lp but not in map_cb # 4) unmatched layers in both lp and map_cb testcases = ( ('fixture_cookbook_1map_5layers.json', ("mainmap-tran-rds-ln-s0-allmaps")), ('fixture_cookbook_1map_3layers.json', ("locationmap_stle_stl_pt_s0_locationmaps")), ('fixture_cookbook_1map_mismatch_layers.json', ("mainmap-tran-rds-ln-s0-allmaps", "locationmap_stle_stl_pt_s0_locationmaps")), ) for cb_file, strings_in_ex_msg in testcases: cmf.map_definitions = os.path.join(self.parent_dir, 'tests', 'testfiles', cb_file) with self.assertRaises(ValueError) as ve: MapCookbook(cmf, test_lp, verify_on_creation=True) if six.PY2: self.assertRegexpMatches( str(ve.exception), "One or more layer names occur in only one of these files") for s in strings_in_ex_msg: self.assertRegexpMatches(str(ve.exception), s) else: self.assertRegex( str(ve.exception), "One or more layer names occur in only one of these files") for s in strings_in_ex_msg: self.assertRegex(str(ve.exception), s)
def get_cookbook(**kwargs): lyrs = LayerProperties(my_runner.cmf, my_runner.get_lyr_render_extension(), verify_on_creation) my_cookbook = MapCookbook(my_runner.cmf, lyrs, verify_on_creation, my_runner.hum_event) selected_product_steps = [] for recipe in select_recipes(my_cookbook, map_number): logger.debug('About to create steps for recipe {}'.format(recipe.mapnumber)) selected_product_steps.append(_get_product_start_step(recipe)) selected_product_steps.extend(data_search.get_per_product_data_search_steps( my_runner, recipe)) # This is a crude implenmentaiton of dry-run for now. if not dry_run: selected_product_steps.extend(_get_per_product_runner_steps(my_runner, recipe)) selected_product_steps.append(_get_product_end_step(recipe)) return selected_product_steps
def setUp(self): self.parent_dir = os.path.dirname( os.path.dirname(os.path.realpath(__file__))) self.cmf_descriptor_path = os.path.join( self.parent_dir, 'example', 'cmf_description_flat_test.json') self.cmf = CrashMoveFolder(self.cmf_descriptor_path, verify_on_creation=False) self.event_descriptor_path = os.path.join(self.parent_dir, 'example', 'event_description.json') self.event = Event(self.event_descriptor_path) # self.cmf = CrashMoveFolder(self.cmf_descriptor_path) self.lyr_props = LayerProperties(self.cmf, '', verify_on_creation=False) self.recipe_descriptor_path = os.path.join( self.parent_dir, 'example', 'example_single_map_recipe.json') with open(self.recipe_descriptor_path) as json_file: self.recipe_def = json.load(json_file) self.recipe = MapRecipe(self.recipe_def, self.lyr_props)
def test_select_recipes(self): # This looks for the MapID in the step.running_msg for the selected maps # A list of tuples to test # * The param (as entered by a human) to be passed to `get_cookbook_steps`. Includes upper, lower # and mixed case, MapIDs that aren't in the cookbook etc. Can be either a string or a list # * A list of the mapIDs that should be created (exactly as in the cookbook file - match case etc) # * A list of mapID that should NOT be created (and represent a failure) # # This is the list of mapID that exist in the relevant cookbook # ['MA001', 'MA002', 'MA003', 'MA004'] test_cases = [('ma001', ['MA001'], ['MA002', 'MA003', 'MA004']), ('MA004', ['MA004'], ['MA001', 'MA002', 'MA003']), ('Ma004', ['MA004'], ['MA001', 'MA002', 'MA003']), ('MA001', ['MA001'], ['MA002', 'MA003', 'MA004']), (['mA001', 'ma002'], ['MA001', 'MA002'], ['MA003', 'MA004']), ('ma999', [], ['MA001', 'MA002', 'MA003', 'MA004']), (None, ['MA001', 'MA002', 'MA003', 'MA004'], [])] cmf = CrashMoveFolder(self.path_to_cmf_file) lp = LayerProperties(cmf, 'test', False) cb = MapCookbook(cmf, lp, False) for mapid_arg, should_create, fail_list in test_cases: # print('mapid_arg = {}'.format(mapid_arg)) # print('should_create = {}'.format(should_create)) # print('fail_list = {}'.format(fail_list)) should_create_set = set(should_create) selected_recipes = plugin_controller.select_recipes(cb, mapid_arg) selected_map_ids = set( [recipe.mapnumber.upper() for recipe in selected_recipes]) # Check that no MapID were selected that shouldn't have been: self.assertTrue(selected_map_ids.isdisjoint(fail_list)) # Check that all of the `selected_ids` match the `should_create` set: self.assertEqual(should_create_set, selected_map_ids)
def test_layer_props_and_cmf_mismatch(self): # create and test_cmf and test_lp which refer different layer_prop.json files cmf1 = CrashMoveFolder(self.path_to_valid_cmf_des) test_lp = LayerProperties(cmf1, "test", verify_on_creation=False) # now point the test_cmf to a different layer_props.json cmf2 = CrashMoveFolder(self.path_to_valid_cmf_des) cmf2.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_layer_properties_four_layers.json') # check that a ValueError is raised when `verify_on_creation=True` with self.assertRaises(ValueError) as ve: MapCookbook(cmf2, test_lp, verify_on_creation=True) if six.PY2: self.assertRegexpMatches(str(ve.exception), "strange results") else: self.assertRegex(str(ve.exception), "strange results") # check that a ValueError is not raised when `verify_on_creation=False` test_mcb = MapCookbook(cmf2, test_lp, verify_on_creation=False) self.assertIsInstance(test_mcb, MapCookbook)
def test_load_recipe_with_layer_props_inc(self): # Test that a MapRecipe read form json with only a layername, combined with the # relevant LayerProperties is equal to a MapRecipe with all of the layerdetails embeded. # layerpros with cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json') test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) # recipe with layer name only recipe1 = MapRecipe(fixtures.recipe_with_layer_name_only, test_lp) # combined recipe with layer props recipe2 = MapRecipe(fixtures.recipe_with_layer_details_embedded, test_lp) self.assertEqual(recipe1, recipe2) # 2) with non-matching layer props schema recipe3 = MapRecipe(fixtures.recipe_with_positive_iso3_code, test_lp) self.assertNotEqual(recipe1, recipe3)
def test_layer_data_schema(self): null_schema = True passing_schema = yaml.safe_load(r""" required: - name_en properties: geometry_type: items: enum: - MultiPolygon - Polygon additionalItems: false crs: items: enum: - EPSG:2090 additionalItems: false """) # Note the missing `enum` blocks failing_schema = yaml.safe_load(r""" required: - name_en properties: geometry_type: items: - MultiPolygon - Polygon additionalItems: false crs: items: - EPSG:2090 additionalItems: false """) cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json' ) # Two cases where data schema is valid yaml for test_schema in [null_schema, passing_schema]: with mock.patch('mapactionpy_controller.data_schemas.yaml.safe_load') as mock_safe_load: mock_safe_load.return_value = test_schema test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) MapRecipe(fixtures.recipe_with_positive_iso3_code, test_lp) self.assertTrue(True, 'validated jsonschema') # case where data schema file itself malformed somehow with mock.patch('mapactionpy_controller.data_schemas.yaml.safe_load') as mock_safe_load: mock_safe_load.return_value = failing_schema self.assertRaises( jsonschema.exceptions.SchemaError, MapRecipe, fixtures.recipe_with_positive_iso3_code, test_lp )
def test_verify_with_rendering_files(self): # self.fail() # load a valid CMF test_cmf = CrashMoveFolder(self.path_to_valid_cmf_des) # Overwright the Layer Properties file path with # mapactionpy_controller\tests\testfiles\fixture_layer_properties_four_layers.json test_cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_layer_properties_four_layers.json') layer_rendering_test_root = os.path.join(self.parent_dir, 'tests', 'testfiles', 'test_layer_rendering') test_cmf.layer_rendering # 1) Exact match of .lyr files and layer properties test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_exact_match') lyr_lp = LayerProperties(test_cmf, '.lyr', verify_on_creation=True) self.assertFalse(lyr_lp.is_difference_with_layer_rendering_dir()) qml_lp = LayerProperties(test_cmf, '.qml', verify_on_creation=True) self.assertFalse(qml_lp.is_difference_with_layer_rendering_dir()) # 2) .lyr files which don't have layer properties entries test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'five_files') self.assertRaises(ValueError, LayerProperties, test_cmf, '.lyr') self.assertRaises(ValueError, LayerProperties, test_cmf, '.qml') # 3) layer properties entries which don't have cooresponding .lyr files. test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'three_files') self.assertRaises(ValueError, LayerProperties, test_cmf, '.lyr') self.assertRaises(ValueError, LayerProperties, test_cmf, '.qml') # 4) Both 2 & 3 combined test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_mis_match') self.assertRaises(ValueError, LayerProperties, test_cmf, '.lyr') self.assertRaises(ValueError, LayerProperties, test_cmf, '.qml') # 6) Overrided validation checks in constructor test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_mis_match') long_lived_lp = LayerProperties(test_cmf, '.lyr', verify_on_creation=False) self.assertTrue(long_lived_lp.is_difference_with_layer_rendering_dir()) long_lived_lp.cmf.layer_rendering = os.path.join( layer_rendering_test_root, 'four_files_exact_match') self.assertFalse( long_lived_lp.is_difference_with_layer_rendering_dir()) # 7) Same results whether or not the '.' character is included in the file extension test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_exact_match') # passing example with dot lyr_lp = LayerProperties(test_cmf, '.lyr', verify_on_creation=True) self.assertFalse(lyr_lp.is_difference_with_layer_rendering_dir()) # passing example without dot lyr_lp = LayerProperties(test_cmf, 'lyr', verify_on_creation=True) self.assertFalse(lyr_lp.is_difference_with_layer_rendering_dir()) # failing example with dot test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_mis_match') self.assertRaises(ValueError, LayerProperties, test_cmf, '.lyr') # failing example without dot test_cmf.layer_rendering = os.path.join(layer_rendering_test_root, 'four_files_mis_match') self.assertRaises(ValueError, LayerProperties, test_cmf, 'lyr')
def test_filter_lyr_for_use_in_frame_extent(self): # Have included the digit at the start of the string, so that can be sorted easily. cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json') test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) # recipe with layer name only with open( os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_cookbook_1map_5layers_1frame.json')) as rf: cookbook_def = json.load(rf) # get the first (only) recipe in the cookbook recipe_def = cookbook_def['recipes'].pop() generic_lyr_def = json.loads('''{ "name": "the_name", "reg_exp": "^wrl_admn_ad0_py_(.*?)_(.*?)_([phm][phm])(.+)shp$", "schema_definition": "admin1_reference.yml", "definition_query": "", "display": true, "add_to_legend": true, "label_classes": [] }''') # Case 1 # test white list test_white_list1 = [('1a', True), ('1b', False), ('1c', None), ('1d', True), ('1e', False)] expected_white_result1 = ['1a', '1d'] test_white_list2 = [('2a', True), ('2b', None), ('2c', None), ('2d', True), ('2e', None)] expected_white_result2 = ['2a', '2d'] # Case 2 # Black List test_black_list = [('3a', None), ('3b', False), ('3c', None), ('3d', None), ('3e', False)] expected_black_result = ['3a', '3c', '3d'] # Case 3 # Default test_default_list = [('4a', None), ('4b', None), ('4c', None), ('4d', None), ('4e', None)] expected_default_result = ['4a', '4b', '4c', '4d', '4e'] all_test_params = [(test_white_list1, expected_white_result1), (test_white_list2, expected_white_result2), (test_black_list, expected_black_result), (test_default_list, expected_default_result)] for test_list, expected_result in all_test_params: test_recipe = MapRecipe(recipe_def, test_lp) # Build up a mock list of layer to test replacement_lyrs = [] for test_lyr_details in test_list: new_lyr = RecipeLayer(generic_lyr_def, test_lp, verify_on_creation=False) new_lyr.name = test_lyr_details[0] new_lyr.use_for_frame_extent = test_lyr_details[1] # vaugely near Lebanon new_lyr.extent = (35, 33, 36, 34) new_lyr.crs = 'epsg:4326' replacement_lyrs.append(new_lyr) test_frame = test_recipe.map_frames.pop() test_frame.layers = replacement_lyrs result_lyrs = test_frame._filter_lyr_for_use_in_frame_extent() actual_result = [lyr.name for lyr in result_lyrs] self.assertEqual(actual_result, expected_result)
def main(args): args = parser.parse_args() event = Event(args.eventDescriptionFile) runner = ArcProRunner(event) recipe_without_positive_iso3_code = ('''{ "mapnumber": "MA001", "category": "Reference", "product": "DJI Overview Map", "summary": "Overview of DJI with topography displayed", "export": true, "template": "reference", "map_frames": [ { "name": "Main map", "layers": [ { "name": "mainmap-stle-stl-pt-s0-allmaps", "reg_exp": "^[a-z][a-z][a-z]_stle_stl_pt_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "stle_ste_pt.yml", "definition_query": "fclass IN ('national_capital', 'city', 'capital', 'town')", "display": true, "add_to_legend": true, "label_classes": [ { "class_name": "National Capital", "expression": "[name]", "sql_query": "('fclass' = 'national_capital')", "show_class_labels": true }, { "class_name": "Admin 1 Capital", "expression": "[name]", "sql_query": "('fclass' = 'town')", "show_class_labels": true } ] }, { "name": "mainmap-carto-fea-py-s0-allmaps", "reg_exp": "^[a-z][a-z][a-z]_carto_fea_py_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "null-schema.yml", "definition_query": "", "display": true, "add_to_legend": false, "label_classes": [] }, { "name": "mainmap-elev-cst-ln-s0-allmaps", "reg_exp": "^[a-z][a-z][a-z]_elev_cst_ln_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "null-schema.yml", "definition_query": "", "display": true, "add_to_legend": false, "label_classes": [] }, { "name": "mainmap-admn-ad0-ln-s0-reference", "reg_exp": "^[a-z][a-z][a-z]_admn_ad0_ln_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "null-schema.yml", "definition_query": "", "display": true, "add_to_legend": false, "label_classes": [] }, { "name": "mainmap-admn-ad1-ln-s0-reference", "reg_exp": "^[a-z][a-z][a-z]_admn_ad1_ln_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "admin1_reference.yml", "definition_query": "", "display": true, "add_to_legend": true, "label_classes": [] }, { "name": "mainmap-phys-riv-ln-s0-reference", "reg_exp": "^[a-z][a-z][a-z]_phys_riv_ln_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "null-schema.yml", "definition_query": "", "display": true, "add_to_legend": true, "label_classes": [] }, { "name": "mainmap-admn-ad1-py-s0-reference", "reg_exp": "^[a-z][a-z][a-z]_admn_ad1_py_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "admin1_reference.yml", "definition_query": "", "display": true, "add_to_legend": true, "label_classes": [] }, { "name": "mainmap-admn-ad0-ln-s0-surroundingcountries", "reg_exp": "^[a-z][a-z][a-z]_admn_ad0_ln_(.*?)_(.*?)_([phm][phm])(.*?).shp$", "schema_definition": "null-schema.yml", "definition_query": "", "display": true, "add_to_legend": true, "label_classes": [] } ] } ] }''') layerProperties = LayerProperties(event.cmf_descriptor_path, '.lyr', verify_on_creation=False) recipe = MapRecipe(recipe_without_positive_iso3_code, layerProperties) recipe = runner.get_templates(state=recipe) recipe = runner.create_ouput_map_project(state=recipe) recipe = runner.build_project_files(state=recipe) themes = set() themes.add("Health") propertiesDict = {} propertiesDict['themes'] = themes propertiesDict['accessnotes'] = "My super access note" recipe = runner.export_maps(state=recipe, properties=propertiesDict)
def test_get_map_frame_extents(self): cmf = CrashMoveFolder( os.path.join(self.parent_dir, 'example', 'cmf_description_relative_paths_test.json')) cmf.layer_properties = os.path.join( self.parent_dir, 'tests', 'testfiles', 'cookbooks', 'fixture_layer_properties_for_atlas.json') test_lp = LayerProperties(cmf, ".lyr", verify_on_creation=False) # recipe with layer name only with open( os.path.join( self.parent_dir, 'tests', 'testfiles', 'fixture_cookbook_1map_5layers_1frame.json')) as rf: cookbook_def = json.load(rf) # get the first (only) recipe in the cookbook recipe_def = cookbook_def['recipes'].pop() generic_lyr_def = json.loads('''{ "name": "the_name", "reg_exp": "^wrl_admn_ad0_py_(.*?)_(.*?)_([phm][phm])(.+)shp$", "schema_definition": "admin1_reference.yml", "definition_query": "", "display": true, "add_to_legend": true, "label_classes": [] }''') # Case 1 # One or more layers does not have it's extent defined case1_list = [('case1_lyrA', (35, 33, 36, 34), 'epsg:4326'), ('case1_lyrB', None, None)] case1_result = (35, 33, 36, 34) # Case 2 # Simple union with two lyrs of same crs case2_list = [('case2_lyrA', (33, 51, 36, 58), 'epsg:4326'), ('case2_lyrB', (15, 52, 35, 55), 'epsg:4326')] case2_result = (15, 51, 36, 58) # Case 3 # Union with two lyrs of with different crs # 'epsg:4326'== WGS1984, 'epsg:3785' == Web Mercator case3_list = [('case3_lyrA', (33, 51, 36, 58), 'epsg:4326'), ('case3_lyrB', (1669792.36, 6800125.45, 3896182.18, 7361866.11), 'epsg:3785')] case3_result = (15, 51, 36, 58) # Case 4 # One layer which stradles 180 degree meridian all_test_params = [(case1_list, case1_result), (case2_list, case2_result), (case3_list, case3_result)] for test_list, expected_result in all_test_params: test_recipe = MapRecipe(recipe_def, test_lp) # Build up a mock list of layer to test replacement_lyrs = [] for name, extent, crs in test_list: new_lyr = RecipeLayer(generic_lyr_def, test_lp, verify_on_creation=False) new_lyr.name = name new_lyr.use_for_frame_extent = bool(extent) # vaugely near Lebanon new_lyr.extent = extent new_lyr.crs = crs replacement_lyrs.append(new_lyr) # print('test_get_map_frame_extents') # print('expected_result = {}'.format(expected_result)) test_frame = test_recipe.map_frames.pop() test_frame.crs = 'epsg:4326' test_frame.layers = replacement_lyrs test_frame.calc_extent(state=test_recipe) actual_result = test_frame.extent # print('actual_result = {}'.format(actual_result)) for actual, expected in zip(actual_result, expected_result): self.assertAlmostEqual(actual, expected)