<commit_before># -*- coding: utf-8 -*-
from unittest import TestCase


def setUpModule():
    import c2cgeoportal
    c2cgeoportal.schema = 'main'
    c2cgeoportal.srid = 21781


class TestEntryView(TestCase):

    def test__get_child_layers_info(self):
        import math
        from pyramid.testing import DummyRequest
        from c2cgeoportal.views.entry import Entry

        request = DummyRequest()
        entry = Entry(request)

        class Layer(object):
            pass

        child_layer_1 = Layer()
        child_layer_1.name = 'layer_1'
        child_layer_1.scaleHint = {
                'min': 1 * math.sqrt(2),
                'max': 2 * math.sqrt(2)
                }
        child_layer_1.layers = []

        child_layer_2 = Layer()
        child_layer_2.name = 'layer_2'
        child_layer_2.scaleHint = {
                'min': 3 * math.sqrt(2),
                'max': 4 * math.sqrt(2)
                }
        child_layer_2.layers = []

        layer = Layer()
        layer.layers = [child_layer_1, child_layer_2]

        child_layers_info = entry._get_child_layers_info(layer)

        expected = [{
            'name': 'layer_1',
            'minResolutionHint': 1.0,
            'maxResolutionHint': 2.0
            }, {
            'name': 'layer_2',
            'minResolutionHint': 3.0,
            'maxResolutionHint': 4.0
            }]
        self.assertEqual(child_layers_info, expected)<commit_msg>entry view - add a unit test for get_child_layers_info for the case where there is no scaleHint<commit_after># -*- coding: utf-8 -*-
from unittest import TestCase


def setUpModule():
    import c2cgeoportal
    c2cgeoportal.schema = 'main'
    c2cgeoportal.srid = 21781


class TestEntryView(TestCase):

    def test__get_child_layers_info_with_scalehint(self):
        import math
        from pyramid.testing import DummyRequest
        from c2cgeoportal.views.entry import Entry

        request = DummyRequest()
        entry = Entry(request)

        class Layer(object):
            pass

        child_layer_1 = Layer()
        child_layer_1.name = 'layer_1'
        child_layer_1.scaleHint = {
                'min': 1 * math.sqrt(2),
                'max': 2 * math.sqrt(2)
                }
        child_layer_1.layers = []

        child_layer_2 = Layer()
        child_layer_2.name = 'layer_2'
        child_layer_2.scaleHint = {
                'min': 3 * math.sqrt(2),
                'max': 4 * math.sqrt(2)
                }
        child_layer_2.layers = []

        layer = Layer()
        layer.layers = [child_layer_1, child_layer_2]

        child_layers_info = entry._get_child_layers_info(layer)

        expected = [{
            'name': 'layer_1',
            'minResolutionHint': 1.0,
            'maxResolutionHint': 2.0
            }, {
            'name': 'layer_2',
            'minResolutionHint': 3.0,
            'maxResolutionHint': 4.0
            }]
        self.assertEqual(child_layers_info, expected)

    def test__get_child_layers_info_without_scalehint(self):
        from pyramid.testing import DummyRequest
        from c2cgeoportal.views.entry import Entry

        request = DummyRequest()
        entry = Entry(request)

        class Layer(object):
            pass

        child_layer_1 = Layer()
        child_layer_1.name = 'layer_1'
        child_layer_1.scaleHint = None
        child_layer_1.layers = []

        child_layer_2 = Layer()
        child_layer_2.name = 'layer_2'
        child_layer_2.scaleHint = None
        child_layer_2.layers = []

        layer = Layer()
        layer.layers = [child_layer_1, child_layer_2]

        child_layers_info = entry._get_child_layers_info(layer)

        expected = [{
            'name': 'layer_1'
            }, {
            'name': 'layer_2',
            }]
        self.assertEqual(child_layers_info, expected)
{'fraction_non_alphanumeric': 0.09914574165156614, 'fraction_numerical': 0.024592285788247476, 'mean_word_length': 1.8432671081677705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5754779', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1159, 'n_words': 223}