コード例 #1
0
ファイル: arche.py プロジェクト: codacy-badger/arche
 def get_items(
     source: Union[str, pd.DataFrame, RawItems],
     start: int,
     count: Optional[int],
     filters: Optional[api.Filters],
     expand: bool,
 ) -> Union[JobItems, CollectionItems]:
     if isinstance(source, pd.DataFrame):
         return Items.from_df(source, expand=expand)
     elif isinstance(source, Iterable) and not isinstance(source, str):
         return Items.from_array(source, expand=expand)
     elif helpers.is_job_key(source):
         return JobItems(key=source,
                         start=start,
                         count=count,
                         filters=filters,
                         expand=expand)
     elif helpers.is_collection_key(source):
         if start:
             raise ValueError(
                 "Collections API does not support 'start' parameter")
         return CollectionItems(key=source,
                                count=count,
                                filters=filters,
                                expand=expand)
     else:
         raise ValueError(
             f"'{source}' is not a valid job or collection key")
コード例 #2
0
def test_job_items(mocker):
    mocker.patch("arche.readers.items.JobItems.job", return_value=Job(), autospec=True)
    mocker.patch(
        "arche.tools.api.get_items", return_value=job_items[1:3], autospec=True
    )
    items = JobItems(key="112358/13/21", count=2, start_index=1, filters=None)
    np.testing.assert_array_equal(items.raw, job_items[1:3])
    pd.testing.assert_frame_equal(items.df, expected_job_df.iloc[1:3])
    assert items.count == 2
    assert items.start == "112358/13/21/1"
コード例 #3
0
ファイル: conftest.py プロジェクト: vipulgupta2048/arche
def get_job_items_mock(mocker, items=default_items, key="a_key"):
    mocker.patch(
        "arche.readers.items.JobItems.job",
        return_value=Job(items=items),
        autospec=False,
    )
    mocker.patch("arche.readers.items.JobItems.fetch_data",
                 return_value=items,
                 autospec=False)
    job_items = JobItems(key=key, count=len(items))
    return job_items
コード例 #4
0
ファイル: conftest.py プロジェクト: vipulgupta2048/arche
def get_job_items(request, mocker):
    mocker.patch("arche.readers.items.JobItems.job",
                 return_value=get_job,
                 autospec=True)
    mocker.patch(
        "arche.readers.items.JobItems.fetch_data",
        return_value=request.param,
        autospec=True,
    )

    job_items = JobItems(key="112358/13/21", count=len(request.param))
    return job_items
コード例 #5
0
def get_job_items(mocker):
    mocker.patch("arche.readers.items.JobItems.job",
                 return_value=get_job,
                 autospec=True)
    raw_data = deepcopy(CLOUD_ITEMS)
    mocker.patch(
        "arche.readers.items.JobItems.fetch_data",
        return_value=np.array(raw_data),
        autospec=True,
    )
    job_items = JobItems(key="112358/13/21", count=len(raw_data))
    return job_items
コード例 #6
0
ファイル: arche.py プロジェクト: zanachka/arche
 def get_items(
     source: Union[str, pd.DataFrame, RawItems],
     count: Optional[int],
     start: Optional[str],
     filters: Optional[api.Filters],
 ) -> Items:
     if isinstance(source, pd.DataFrame):
         return Items.from_df(source)
     elif isinstance(source, Iterable) and not isinstance(source, str):
         return Items.from_array(cast(RawItems, source))
     elif helpers.is_job_key(source):
         return JobItems(source, count, int(start or 0), filters)
     elif helpers.is_collection_key(source):
         return CollectionItems(source, count, start, filters)
     else:
         raise ValueError(
             f"'{source}' is not a valid job or collection key")
コード例 #7
0
ファイル: test_items.py プロジェクト: codacy-badger/arche
def test_job_items(mocker, start, count, expected_count):
    mocker.patch("arche.readers.items.JobItems.job",
                 return_value=Job(),
                 autospec=True)
    mocker.patch(
        "arche.tools.api.get_items",
        return_value=job_items[start:expected_count],
        autospec=True,
    )
    items = JobItems(key="112358/13/21",
                     start=start,
                     count=count,
                     filters=None,
                     expand=False)
    np.testing.assert_array_equal(items.raw, job_items[start:count])
    pd.testing.assert_frame_equal(
        items.df, expected_job_items.iloc[start:count].reset_index(drop=True))
    assert items.count == count
コード例 #8
0
 def get_items(
     source: str,
     start: int,
     count: Optional[int],
     filters: Optional[api.Filters],
     expand: bool,
 ) -> Union[JobItems, CollectionItems]:
     if helpers.is_job_key(source):
         return JobItems(
             key=source, start=start, count=count, filters=filters, expand=expand
         )
     elif helpers.is_collection_key(source):
         if start:
             raise ValueError("Collections API does not support 'start' parameter")
         return CollectionItems(
             key=source, count=count, filters=filters, expand=expand
         )
     else:
         raise ValueError(f"'{source}' is not a valid job or collection key")