Пример #1
0
class NorthAmericanPlantDistributionMapTestCase(TestCase):
    def setUp(self):
        self.distribution_map = NorthAmericanPlantDistributionMap()
        create_distribution_records()

    def test_is_correct_map(self):
        self.assertEqual('North American Distribution Map',
                         self.distribution_map.get_title())

    def test_distribution_areas_are_shaded_correctly(self):
        SCIENTIFIC_NAME = 'Dendrolycopodium dendroideum'
        COLORS = Legend.COLORS
        # Currently, data for North America are only available at the
        # state, province, and territory level.
        EXPECTED_SHADED_AREAS = {
            'CT': COLORS['native'],
            'MA': COLORS['native'],
            'ME': COLORS['native'],
            'NH': COLORS['native'],
            'NJ': COLORS['native'],
            'NY': COLORS['native'],
            'PA': COLORS['native'],
            'NC': COLORS['native'],
            'RI': COLORS['native'],
            'VT': COLORS['native'],
            'NS': COLORS['native'],
            'NB': COLORS['native'],
            'QC': COLORS['native'],
            'ON': COLORS['native'],
            'MB': COLORS['native'],
            'SK': COLORS['native'],
            'AB': COLORS['native'],
            'BC': COLORS['native'],
            }
        self.distribution_map.set_plant(SCIENTIFIC_NAME)
        records = (self.distribution_map._get_distribution_records(
                   SCIENTIFIC_NAME))
        self.assertTrue(len(records) > 0)
        self.distribution_map.shade()
        path_nodes = self.distribution_map.svg_map.xpath(
            'svg:g/svg:path', namespaces=NAMESPACES)
        paths = [Path(path_node) for path_node in path_nodes]
        shaded_paths = []
        for path in paths:
            style = path.get_style()
            if style.find('fill:#') > -1 and style.find('fill:#fff') == -1:
                shaded_paths.append(path)
        # There can be more shaded paths than expected shaded areas.
        # Example: BC has two paths, one for the mainland and one for
        # Vancouver Island.
        self.assertTrue(len(shaded_paths) >= len(EXPECTED_SHADED_AREAS))
        # Check that each shaded area and its color is expected.
        for path in shaded_paths:
            path_id = path.path_node.get('id')
            area_key = path_id[0:2]
            self.assertTrue(area_key in EXPECTED_SHADED_AREAS.keys())
            expected_color = EXPECTED_SHADED_AREAS[area_key]
            fill_declaration = 'fill:%s' % expected_color
            self.assertTrue(path.get_style().find(fill_declaration) > -1)
Пример #2
0
def north_american_distribution_map(request, genus, epithet):
    """Return a vector map of North America showing county-level
    distribution data for a plant.
    """
    distribution_map = NorthAmericanPlantDistributionMap()
    return _distribution_map(request, distribution_map, genus, epithet)
Пример #3
0
 def setUp(self):
     self.distribution_map = NorthAmericanPlantDistributionMap()
     create_distribution_records()
Пример #4
0
 def setUp(self):
     self.distribution_map = NorthAmericanPlantDistributionMap()
     create_distribution_records()
Пример #5
0
class NorthAmericanPlantDistributionMapTestCase(TestCase):
    def setUp(self):
        self.distribution_map = NorthAmericanPlantDistributionMap()
        create_distribution_records()

    def _get_shaded_paths(self, distribution_map):
        path_nodes = distribution_map.svg_map.xpath('svg:g/svg:path',
                                                    namespaces=NAMESPACES)
        paths = [Path(path_node) for path_node in path_nodes]
        shaded_paths = []
        for path in paths:
            style = path.get_style()
            if style.find('fill:#') > -1 and style.find('fill:#fff') == -1:
                shaded_paths.append(path)
        return shaded_paths

    def _verify_number_expected_shaded_areas(self, expected_shaded_areas,
                                             shaded_paths):
        # Verify that the number of expected shaded areas is found, at a
        # minimum, among the full list of shaded paths.
        # There can be more shaded paths than expected shaded areas.
        # Example: BC has two paths, one for the mainland and one for
        # Vancouver Island.
        #
        # To debug a failing test, uncomment the following line and run
        # the failing test alone:
        #print 'shaded_paths: %d  expected_shaded_areas: %d' % (
        #    len(shaded_paths), len(expected_shaded_areas))
        self.assertTrue(len(shaded_paths) >= len(expected_shaded_areas))

    def _verify_expected_shaded_areas(self, expected_shaded_areas,
                                      shaded_paths):
        # Check that each shaded area and its color is expected.
        for path in shaded_paths:
            path_id = path.path_node.get('id')
            area_key = path_id[0:2]
            self.assertTrue(area_key in expected_shaded_areas.keys())
            label = expected_shaded_areas[area_key]
            # To debug a failing test, uncomment the following line and
            # run the failing test alone:
            #print 'area_key: %s  label: %s' % (area_key, label)
            fill_declaration = 'fill:%s' % Legend.COLORS[label]
            self.assertTrue(path.get_style().find(fill_declaration) > -1)

    def test_is_correct_map(self):
        self.assertEqual('North American Distribution Map',
                         self.distribution_map.get_title())

    def test_distribution_areas_are_shaded_correctly(self):
        SCIENTIFIC_NAME = 'Dendrolycopodium dendroideum'
        # Currently, data for North America are only available at the
        # state, province, and territory level.
        EXPECTED_SHADED_AREAS = {
            'CT': 'native',
            'MA': 'native',
            'ME': 'native',
            'NH': 'native',
            'NJ': 'native',
            'NY': 'native',
            'PA': 'native',
            'NC': 'native',
            'RI': 'native',
            'VT': 'native',
            'NS': 'native',
            'NB': 'native',
            'QC': 'native',
            'ON': 'native',
            'MB': 'native',
            'SK': 'native',
            'AB': 'native',
            'BC': 'native',
        }
        self.distribution_map.set_plant(SCIENTIFIC_NAME)
        records = (
            self.distribution_map._get_distribution_records(SCIENTIFIC_NAME))
        self.assertTrue(len(records) > 0)
        self.distribution_map.shade()
        shaded_paths = self._get_shaded_paths(self.distribution_map)
        self._verify_number_expected_shaded_areas(EXPECTED_SHADED_AREAS,
                                                  shaded_paths)
        self._verify_expected_shaded_areas(EXPECTED_SHADED_AREAS, shaded_paths)

    def test_county_level_native_overrides_state_level_non_native(self):
        # Ensure that if a plant is marked non-native at the state
        # level, but native in one or more counties, that the state is
        # then overridden to be shaded as native on the map.
        SCIENTIFIC_NAME = 'Leptochloa fusca'
        EXPECTED_SHADED_AREAS = {
            'CT': 'native',
            'MA': 'native',
            'ME': 'non-native',
            'NH': 'native',
            'RI': 'native',
            'VT': 'native',
        }
        self.distribution_map.set_plant(SCIENTIFIC_NAME)
        records = (
            self.distribution_map._get_distribution_records(SCIENTIFIC_NAME))
        self.assertTrue(len(records) > 0)
        self.distribution_map.shade()
        shaded_paths = self._get_shaded_paths(self.distribution_map)
        self._verify_number_expected_shaded_areas(EXPECTED_SHADED_AREAS,
                                                  shaded_paths)
        self._verify_expected_shaded_areas(EXPECTED_SHADED_AREAS, shaded_paths)
Пример #6
0
class NorthAmericanPlantDistributionMapTestCase(TestCase):
    def setUp(self):
        self.distribution_map = NorthAmericanPlantDistributionMap()
        create_distribution_records()

    def _get_shaded_paths(self, distribution_map):
        path_nodes = distribution_map.svg_map.xpath(
            'svg:g/svg:path', namespaces=NAMESPACES)
        paths = [Path(path_node) for path_node in path_nodes]
        shaded_paths = []
        for path in paths:
            style = path.get_style()
            if style.find('fill:#') > -1 and style.find('fill:#fff') == -1:
                shaded_paths.append(path)
        return shaded_paths

    def _verify_number_expected_shaded_areas(self, expected_shaded_areas,
            shaded_paths):
        # Verify that the number of expected shaded areas is found, at a
        # minimum, among the full list of shaded paths.
        # There can be more shaded paths than expected shaded areas.
        # Example: BC has two paths, one for the mainland and one for
        # Vancouver Island.
        #
        # To debug a failing test, uncomment the following line and run
        # the failing test alone:
        #print 'shaded_paths: %d  expected_shaded_areas: %d' % (
        #    len(shaded_paths), len(expected_shaded_areas))
        self.assertTrue(len(shaded_paths) >= len(expected_shaded_areas))

    def _verify_expected_shaded_areas(self, expected_shaded_areas,
            shaded_paths):
        # Check that each shaded area and its color is expected.
        for path in shaded_paths:
            path_id = path.path_node.get('id')
            area_key = path_id[0:2]
            self.assertTrue(area_key in expected_shaded_areas.keys())
            label = expected_shaded_areas[area_key]
            # To debug a failing test, uncomment the following line and
            # run the failing test alone:
            #print 'area_key: %s  label: %s' % (area_key, label)
            fill_declaration = 'fill:%s' % Legend.COLORS[label]
            self.assertTrue(path.get_style().find(fill_declaration) > -1)

    def test_is_correct_map(self):
        self.assertEqual('North American Distribution Map',
                         self.distribution_map.get_title())

    def test_distribution_areas_are_shaded_correctly(self):
        SCIENTIFIC_NAME = 'Dendrolycopodium dendroideum'
        # Currently, data for North America are only available at the
        # state, province, and territory level.
        EXPECTED_SHADED_AREAS = {
            'CT': 'native',
            'MA': 'native',
            'ME': 'native',
            'NH': 'native',
            'NJ': 'native',
            'NY': 'native',
            'PA': 'native',
            'NC': 'native',
            'RI': 'native',
            'VT': 'native',
            'NS': 'native',
            'NB': 'native',
            'QC': 'native',
            'ON': 'native',
            'MB': 'native',
            'SK': 'native',
            'AB': 'native',
            'BC': 'native',
            }
        self.distribution_map.set_plant(SCIENTIFIC_NAME)
        records = (self.distribution_map._get_distribution_records(
                   SCIENTIFIC_NAME))
        self.assertTrue(len(records) > 0)
        self.distribution_map.shade()
        shaded_paths = self._get_shaded_paths(self.distribution_map)
        self._verify_number_expected_shaded_areas(EXPECTED_SHADED_AREAS,
            shaded_paths)
        self._verify_expected_shaded_areas(EXPECTED_SHADED_AREAS,
            shaded_paths)

    def test_county_level_native_overrides_state_level_non_native(self):
        # Ensure that if a plant is marked non-native at the state
        # level, but native in one or more counties, that the state is
        # then overridden to be shaded as native on the map.
        SCIENTIFIC_NAME = 'Leptochloa fusca'
        EXPECTED_SHADED_AREAS = {
            'CT': 'native',
            'MA': 'native',
            'ME': 'non-native',
            'NH': 'native',
            'RI': 'native',
            'VT': 'native',
        }
        self.distribution_map.set_plant(SCIENTIFIC_NAME)
        records = (self.distribution_map._get_distribution_records(
                   SCIENTIFIC_NAME))
        self.assertTrue(len(records) > 0)
        self.distribution_map.shade()
        shaded_paths = self._get_shaded_paths(self.distribution_map)
        self._verify_number_expected_shaded_areas(EXPECTED_SHADED_AREAS,
            shaded_paths)
        self._verify_expected_shaded_areas(EXPECTED_SHADED_AREAS,
            shaded_paths)