Download pool/shard001/Python/0009181_test_managers.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 2.72 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009181_test_managers.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/Python/0009181_test_managers.py
-
curl -L -o 0009181_test_managers.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009181_test_managers.py
2.72 kB
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Test Managers | |
| ------------- | |
| Tests for `django-cursor-pagination` managers module. | |
| """ | |
| from __future__ import absolute_import | |
| from .base import CursorBaseTestCase | |
| from .models import ExampleModel | |
| class TestCursorManagerByPrimaryKey(CursorBaseTestCase): | |
| def test_ordering_ascending(self): | |
| qs = ExampleModel.objects.order_by('pk') | |
| first_group = qs[:self.PAGE_SIZE] | |
| cursor = first_group.cursor() | |
| qs2 = qs.from_cursor(cursor) | |
| second_group = qs2[self.PAGE_SIZE:2 * self.PAGE_SIZE] | |
| first_pks = set(x.pk for x in first_group) | |
| second_pks = set(x.pk for x in second_group) | |
| self.assertFalse(first_pks & second_pks) | |
| for count in second_pks: | |
| self.assertGreater( | |
| count, max(first_pks), | |
| "Cursor didn't maintain ordering" | |
| ) | |
| def test_ordering_descending(self): | |
| qs = ExampleModel.objects.order_by('-pk') | |
| first_group = qs[:self.PAGE_SIZE] | |
| cursor = first_group.cursor() | |
| qs2 = qs.from_cursor(cursor) | |
| second_group = qs2[self.PAGE_SIZE:2 * self.PAGE_SIZE] | |
| first_pks = set(x.pk for x in first_group) | |
| second_pks = set(x.pk for x in second_group) | |
| self.assertFalse(first_pks & second_pks) | |
| for count in second_pks: | |
| self.assertLess( | |
| count, min(first_pks), | |
| "Cursor didn't maintain ordering" | |
| ) | |
| class TestCursorManagerByInteger(CursorBaseTestCase): | |
| def test_ordering_ascending(self): | |
| qs = ExampleModel.objects.order_by('count_field') | |
| first_group = qs[:self.PAGE_SIZE] | |
| cursor = first_group.cursor() | |
| qs2 = qs.from_cursor(cursor) | |
| second_group = qs2[self.PAGE_SIZE:2 * self.PAGE_SIZE] | |
| first_counts = set(x.count_field for x in first_group) | |
| second_counts = set(x.count_field for x in second_group) | |
| for count in second_counts: | |
| self.assertGreaterEqual( | |
| count, max(first_counts), | |
| "Cursor didn't maintain ordering" | |
| ) | |
| def test_ordering_descending(self): | |
| qs = ExampleModel.objects.order_by('-count_field') | |
| first_group = qs[:self.PAGE_SIZE] | |
| cursor = first_group.cursor() | |
| qs2 = qs.from_cursor(cursor) | |
| second_group = qs2[self.PAGE_SIZE:2 * self.PAGE_SIZE] | |
| first_counts = set(x.count_field for x in first_group) | |
| second_counts = set(x.count_field for x in second_group) | |
| for count in second_counts: | |
| self.assertLessEqual( | |
| count, min(first_counts), | |
| "Cursor didn't maintain ordering" | |
| ) | |