def test_get_page_number(self, key):
        """Test IndexPage page get_page_number functions."""
        data = self.sites[key]
        index_page = IndexPage(self.site, self.sites[key]["index"])

        # Test get_page_numbers_from_label.
        for label, num_set in data["get_number"]:
            # Get set of numbers from label with label as int or str.
            self.assertEqual(index_page.get_page_number_from_label(label), num_set)
            self.assertEqual(index_page.get_page_number_from_label(str(label)), num_set)

        # Error if label does not exists.
        label, num_set = "dummy label", []
        self.assertRaises(KeyError, index_page.get_page_number_from_label, "dummy label")

        # Test get_page_from_label.
        for label, page_set in data["get_page"]:
            # Get set of pages from label with label as int or str.
            self.assertEqual(index_page.get_page_from_label(label), page_set)
            self.assertEqual(index_page.get_page_from_label(str(label)), page_set)

        # Error if label does not exists.
        self.assertRaises(KeyError, index_page.get_page_from_label, "dummy label")

        # Test consistency of page <-> numbers mapping on last page_set and
        # num_set used.
        for p in page_set:
            n = index_page._numbers_from_page[p]
            self.assertEqual(index_page._page_from_numbers[n], p)
        for n in num_set:
            n = index_page._page_from_numbers[p]
            self.assertEqual(index_page._numbers_from_page[p], n)
Exemplo n.º 2
0
    def test_get_page_and_number(self, key):
        """Test IndexPage page get_page_number functions."""
        data = self.sites[key]
        index_page = IndexPage(self.site, self.sites[key]['index'])

        # Test get_page_numbers_from_label.
        for label, num_set in data['get_number']:
            # Get set of numbers from label with label as int or str.
            self.assertEqual(index_page.get_page_number_from_label(label),
                             num_set)
            self.assertEqual(index_page.get_page_number_from_label(str(label)),
                             num_set)

        # Error if label does not exists.
        label, num_set = 'dummy label', []
        self.assertRaises(KeyError, index_page.get_page_number_from_label,
                          'dummy label')

        # Test get_page_from_label.
        for label, page_set in data['get_page']:
            # Get set of pages from label with label as int or str.
            self.assertEqual(index_page.get_page_from_label(label),
                             page_set)
            self.assertEqual(index_page.get_page_from_label(str(label)),
                             page_set)

        # Error if label does not exists.
        self.assertRaises(KeyError, index_page.get_page_from_label,
                          'dummy label')

        # Test get_page.
        for n in num_set:
            p = index_page.get_page(n)
            self.assertEqual(index_page.get_number(p), n)

        # Test get_number.
        for p in page_set:
            n = index_page.get_number(p)
            self.assertEqual(index_page.get_page(n), p)
    def test_get_page_and_number(self, key):
        """Test IndexPage page get_page_number functions."""
        data = self.sites[key]
        index_page = IndexPage(self.site, self.sites[key]['index'])

        # Test get_page_numbers_from_label.
        for label, num_set in data['get_number']:
            # Get set of numbers from label with label as int or str.
            self.assertEqual(index_page.get_page_number_from_label(label),
                             num_set)
            self.assertEqual(index_page.get_page_number_from_label(str(label)),
                             num_set)

        # Error if label does not exists.
        label, num_set = 'dummy label', []
        self.assertRaises(KeyError, index_page.get_page_number_from_label,
                          'dummy label')

        # Test get_page_from_label.
        for label, page_set in data['get_page']:
            # Get set of pages from label with label as int or str.
            self.assertEqual(index_page.get_page_from_label(label),
                             page_set)
            self.assertEqual(index_page.get_page_from_label(str(label)),
                             page_set)

        # Error if label does not exists.
        self.assertRaises(KeyError, index_page.get_page_from_label, 'dummy label')

        # Test get_page.
        for n in num_set:
            p = index_page.get_page(n)
            self.assertEqual(index_page.get_number(p), n)

        # Test get_number.
        for p in page_set:
            n = index_page.get_number(p)
            self.assertEqual(index_page.get_page(n), p)
Exemplo n.º 4
0
    def test_get_page_number(self, key):
        """Test IndexPage page get_page_number functions."""
        data = self.sites[key]
        index_page = IndexPage(self.site, self.sites[key]['index'])

        # Test get_page_numbers_from_label.
        for label, num_set in data['get_number']:
            # Get set of numbers from label with label as int or str.
            self.assertEqual(index_page.get_page_number_from_label(label),
                             num_set)
            self.assertEqual(index_page.get_page_number_from_label(str(label)),
                             num_set)

        # Error if label does not exists.
        label, num_set = 'dummy label', []
        self.assertRaises(KeyError, index_page.get_page_number_from_label,
                          'dummy label')

        # Test get_page_from_label.
        for label, page_set in data['get_page']:
            # Get set of pages from label with label as int or str.
            self.assertEqual(index_page.get_page_from_label(label),
                             page_set)
            self.assertEqual(index_page.get_page_from_label(str(label)),
                             page_set)

        # Error if label does not exists.
        self.assertRaises(KeyError, index_page.get_page_from_label, 'dummy label')

        # Test consistency of page <-> numbers mapping on last page_set and
        # num_set used.
        for p in page_set:
            n = index_page._numbers_from_page[p]
            self.assertEqual(index_page._page_from_numbers[n], p)
        for n in num_set:
            n = index_page._page_from_numbers[p]
            self.assertEqual(index_page._numbers_from_page[p], n)