Beispiel #1
0
    def test_index(self):
        paging_list = PagingList(gen, LIMIT)

        for i in LIST[::TOTAL_COUNT // 10]:
            assert paging_list.index(i) == LIST.index(i)

        for i in LIST[MIDDLE::TOTAL_COUNT // 10]:
            assert paging_list.index(i, MIDDLE) == LIST.index(i, MIDDLE)

        for i in LIST[:MIDDLE:TOTAL_COUNT // 10]:
            assert paging_list.index(i, 0, MIDDLE) == LIST.index(i, 0, MIDDLE)

        for i in LIST[LIMIT:MIDDLE:TOTAL_COUNT // 10]:
            assert paging_list.index(i, LIMIT,
                                     MIDDLE) == LIST.index(i, LIMIT, MIDDLE)

        with pytest.raises(ValueError):
            assert paging_list.index(-1)

        with pytest.raises(ValueError):
            assert paging_list.index(LIST[100], 1000)

        with pytest.raises(ValueError):
            assert paging_list.index(LIST[100], stop=90)

        with pytest.raises(ValueError):
            assert paging_list.index(LIST[100], 110, 200)
Beispiel #2
0
    def test_count(self):
        paging_list = PagingList(gen, LIMIT)

        for i in LIST[::TOTAL_COUNT // 10]:
            assert paging_list.count(i) == LIST.count(i)

        assert paging_list.count(-1) == LIST.count(-1)
Beispiel #3
0
    def test_setitem(self):
        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        for index in VALID_INDICES:
            paging_list[index] = -1
            target[index] = -1
            assert list(paging_list) == target

        with pytest.raises(IndexError):
            paging_list[TOTAL_COUNT] = -1

        for slicing in SLICES_WITHOUT_STEP:
            paging_list[slicing] = [-1, -1, -1, -1]
            target[slicing] = [-1, -1, -1, -1]
            assert list(paging_list) == target

        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        slicing = slice(0, TOTAL_COUNT, MIDDLE)
        with pytest.raises(ValueError):
            paging_list[slicing] = [-1]

        paging_list[slicing] = [-1, -1]
        target[slicing] = [-1, -1]
        assert list(paging_list) == target
Beispiel #4
0
    def test_insert(self, index):
        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        paging_list.insert(index, -1)
        target.insert(index, -1)
        assert list(paging_list) == target
Beispiel #5
0
    def test_get_items(self, index):
        paging_list = PagingList(gen, LIMIT)

        for _ in range(2):
            items = paging_list._get_items(index)
            assert paging_list._items is items
            assert len(items) == TOTAL_COUNT
Beispiel #6
0
    def test_append(self):
        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        for _ in range(10):
            paging_list.append(-1)
            target.append(-1)
            assert list(paging_list) == target
Beispiel #7
0
    def test_reverse(self):
        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        paging_list.reverse()
        target.reverse()

        assert list(paging_list) == target
Beispiel #8
0
    def test_pop(self):
        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        for index in VALID_INDICES:
            assert paging_list.pop(index) == target.pop(index)
            assert list(paging_list) == target

        with pytest.raises(IndexError):
            paging_list.pop(TOTAL_COUNT)
    def list_urls(self) -> PagingList[Dict[str, str]]:
        """List the data urls in this segment.

        Returns:
            The PagingList of url dict, which key is the sensor name, value is the url.

        """
        urls = PagingList(self._generate_urls, 128)
        urls._repr_maxlevel = 2  # pylint: disable=protected-access
        return urls
Beispiel #10
0
    def test_iadd(self):
        paging_list = PagingList(gen, LIMIT)
        target = LIST.copy()

        paging_list += (1, 2, 3)
        target += (1, 2, 3)
        assert list(paging_list) == target

        paging_list.extend([])
        target.extend([])
        assert list(paging_list) == target
 def _list_data_diffs(self, basehead: str,
                      segment_name: str) -> PagingList[DataDiff]:
     return PagingList(
         lambda offset, limit: self._generate_data_diffs(
             basehead, segment_name, offset, limit),
         128,
     )
    def list_commits(self, revision: Optional[str] = None) -> PagingList[Commit]:
        """List the commits.

        Arguments:
            revision: The information to locate the specific commit, which can be the commit id,
                the branch name, or the tag name.
                If is given, list the commits before the given commit.
                If is not given, list the commits before the current commit.

        Raises:
            TypeError: When the given revision is illegal.

        Returns:
            The PagingList of :class:`commits<.Commit>`.

        """
        if revision is None:
            if self._status.is_draft:
                revision = self._status.branch_name
            else:
                revision = self._status.commit_id

        if not revision:
            raise TypeError("The given revision is illegal")

        return PagingList(
            lambda offset, limit: self._generate_commits(
                revision, offset, limit  # type: ignore[arg-type]
            ),
            128,
        )
    def get_diff(self,
                 *,
                 head: Optional[Union[str, int]] = None) -> DatasetDiff:
        """Get a brief diff between head and its parent commit.

        Arguments:
            head: Target version identification. Type int for draft number, type str for revision.
                If not given, use the current commit id.

        Examples:
            >>> self.get_diff(head="b382450220a64ca9b514dcef27c82d9a")

        Returns:
            The brief diff between head and its parent commit.

        """
        basehead = self._get_basehead(None, head)

        segment_diffs = PagingList(
            lambda offset, limit: self._generate_segment_diffs(
                basehead, offset, limit), 128)

        dataset_diff = DatasetDiff(self.name, segment_diffs)

        return dataset_diff
    def list_data(self) -> PagingList[RemoteData]:
        """List required Data object in a dataset segment.

        Returns:
            The PagingList of :class:`~tensorbay.dataset.data.RemoteData`.

        """
        return PagingList(self._generate_data, 128)
    def list_urls(self) -> PagingList[str]:
        """List the data urls in this segment.

        Returns:
            The PagingList of urls.

        """
        return PagingList(self._generate_urls, 128)
Beispiel #16
0
    def list_benchmarks(self) -> PagingList[Benchmark]:
        """List all benchmarks.

        Returns:
            The list of Benchmark instances.

        """
        return PagingList(self._generate_benmarks, 128)
Beispiel #17
0
    def test_init_all_items(self, index):
        paging_list = PagingList(gen, LIMIT)

        paging_list._init_all_items(index)
        assert len(paging_list._items) == TOTAL_COUNT

        index = index if index >= 0 else 0
        start = index // LIMIT * LIMIT
        stop = start + LIMIT

        for i, item in enumerate(paging_list._items):
            if start <= i < stop:
                assert item.data == LIST[i]
                assert isinstance(item.page, InitPage)
            else:
                assert not hasattr(item, "data")
                assert isinstance(item.page, LazyPage)
Beispiel #18
0
    def list_segment_names(self) -> PagingList[str]:
        """List all segment names of the search result.

        Returns:
            The PagingList of segment names.

        """
        return PagingList(self._generate_segment_names, 128)
Beispiel #19
0
    def test_iter(self):
        paging_list = PagingList(gen, LIMIT)
        iterator = iter(paging_list)
        for i in LIST:
            assert next(iterator) == i

        with pytest.raises(StopIteration):
            next(iterator)
    def list_data_paths(self) -> PagingList[str]:
        """List required data path in a segment in a certain commit.

        Returns:
            The PagingList of data paths.

        """
        return PagingList(self._generate_data_paths, 128)
    def list_segment_names(self) -> PagingList[str]:
        """List all segment names in a certain commit.

        Returns:
            The PagingList of segment names.

        """
        return PagingList(self._generate_segment_names, 128)
    def list_tags(self) -> PagingList[Tag]:
        """List the information of tags.

        Returns:
            The PagingList of :class:`tags<.Tag>`.

        """
        return PagingList(lambda offset, limit: self._generate_tags(None, offset, limit), 128)
Beispiel #23
0
    def list_evaluations(self) -> PagingList[Evaluation]:
        """List all evaluations.

        Returns:
            A list of evaluations.

        """
        return PagingList(self._generate_evaluations, 128)
    def list_branches(self) -> PagingList[Branch]:
        """List the information of branches.

        Returns:
            The PagingList of :class:`branches<.Branch>`.

        """
        return PagingList(lambda offset, limit: self._generate_branches(None, offset, limit), 128)
    def list_frames(self) -> PagingList[Frame]:
        """List required frames in the segment in a certain commit.

        Returns:
            The PagingList of :class:`~tensorbay.dataset.frame.Frame`.

        """
        return PagingList(self._generate_frames, 128)
Beispiel #26
0
    def list_dataset_names(self) -> PagingList[str]:
        """List names of all TensorBay datasets.

        Returns:
            The PagingList of all TensorBay dataset names.

        """
        return PagingList(
            lambda offset, limit: self._generate_dataset_names(
                None, offset, limit), 128)
Beispiel #27
0
    def test_getitem(self):
        paging_list = PagingList(gen, LIMIT)
        for index in VALID_INDICES:
            assert paging_list[index] == LIST[index]

        with pytest.raises(IndexError):
            paging_list[TOTAL_COUNT]

        for slicing in SLICES_WITHOUT_STEP:
            assert list(paging_list[slicing]) == LIST[slicing]
Beispiel #28
0
    def list_auth_storage_configs(self) -> PagingList[StorageConfig]:
        """List auth storage configs.

        Returns:
            The PagingList of all auth storage configs.

        """
        return PagingList(
            lambda offset, limit: self._generate_auth_storage_configs(
                None, offset, limit),
            128,
        )
Beispiel #29
0
    def list_frames(self, segment_name: str) -> PagingList[Frame]:
        """List required frames of the segment with given name.

        Arguments:
            segment_name: Name of the segment.

        Returns:
            The PagingList of :class:`~tensorbay.dataset.frame.Frame`.

        """
        return PagingList(
            lambda offset, limit: self._generate_frames(
                segment_name, offset, limit), 128)
Beispiel #30
0
    def list_data(self, segment_name: str) -> PagingList[RemoteData]:
        """List required data of the segment with given name.

        Arguments:
            segment_name: Name of the segment.

        Returns:
            The PagingList of :class:`~tensorbay.dataset.data.RemoteData`.

        """
        return PagingList(
            lambda offset, limit: self._generate_data(segment_name, offset,
                                                      limit), 128)