Пример #1
0
    def test_sync_ndays(self, repo_ledger, sink_fs: FileRepoFS, missing: Iterator[RepoObjectPath]) -> None:
        src_fs = mock.MagicMock()
        src_fs.find.side_effect = self.mock_find
        pipe: RepoPipe = RepoPipe(repo_ledger, src_fs, sink_fs)

        with mock.patch("edgar.utils.repo.file_repo_fs.FileRepoFS.iterate_missing") as m:
            m.return_value = missing
            pipe.sync()

        for m in missing:
            period_type = m.date_period_type()
            the_date = m.date()
            o: RepoObject = sink_fs.find(period_type, the_date)
            assert ' '.join([str(period_type), str(the_date)]) == next(o.inp(bufsize=1024))
            assert o.exists()

        tracker: CallTracker = CallTracker()
        tracker.add_expected('next_period', [])
        tracker.add_expected('start' , [Date('2021-01-01')])
        tracker.add_expected('record', [Date('2021-07-12'), DatePeriodType.DAY])
        tracker.add_expected('record', [Date('2021-07-13'), DatePeriodType.DAY])
        tracker.add_expected('record', [Date('2021-07-14'), DatePeriodType.DAY])
        tracker.add_expected('end', [Date('2021-08-01')])
        tracker.assertCalls(repo_ledger.mock_calls)

        (beg_date, end_date) = repo_ledger.next_period()
        assert sink_fs.find(DatePeriodType.DAY, beg_date) == None
        assert sink_fs.find(DatePeriodType.DAY, end_date) == None
 def test_find_object_success(self, edgar_fs: tempfile.TemporaryDirectory,
                              repo_format: RepoFormat, the_date: Date,
                              date_period: DatePeriodType, path: List[str]):
     root: Path = Path(edgar_fs.name)
     fs: FileRepoFS = FileRepoFS(root, repo_format)
     obj: FileRepoObject = fs.find(date_period, the_date)
     assert obj.subpath(4) == path
 def test_get_object_success(self, test_fs: tempfile.TemporaryDirectory,
                             repo_format: RepoFormat, obj_path: str):
     root: Path = Path(test_fs.name)
     fs: FileRepoFS = FileRepoFS(root, repo_format)
     obj: FileRepoObject = fs.get_object(obj_path)
     assert obj is not None
     assert obj.path == (root / obj_path).resolve()
 def test_create(self, edgar_fs: tempfile.TemporaryDirectory,
                 repo_format: RepoFormat, the_date: Date,
                 date_period: DatePeriodType, path: List[str]) -> None:
     root: Path = Path(edgar_fs.name)
     fs: FileRepoFS = FileRepoFS(root, repo_format)
     obj: FileRepoObject = fs.create(date_period, the_date)
     assert obj is not None
     assert obj.subpath(4) == path
    def test_new_object(self, edgar_fs: tempfile.TemporaryDirectory,
                        repo_format: RepoFormat, path: str, object_name: str,
                        expected_result: List[str]):
        root: Path = Path(edgar_fs.name)
        fs: FileRepoFS = FileRepoFS(root, repo_format)
        obj: FileRepoObject = fs.new_object(path, object_name)

        assert obj is not None
        assert obj.subpath(4) == expected_result
    def test_find_missing(self, edgar_fs: tempfile.TemporaryDirectory,
                          repo_format: RepoFormat):
        root: Path = Path(edgar_fs.name)
        fs: FileRepoFS = FileRepoFS(root, repo_format)

        holidays_sample: List[Date] = [
            Date('2018-01-01'),
            Date('2018-01-15'),
            Date('2018-02-19'),
            Date('2018-05-13'),
            Date('2018-05-28'),
            Date('2018-07-04'),
            Date('2018-09-03'),
            Date('2018-10-08'),
            Date('2018-11-12'),
            Date('2018-11-22'),
            Date('2018-12-25'),
            Date('2019-01-01'),
            Date('2019-01-21'),
            Date('2019-02-18'),
            Date('2019-05-27'),
        ]

        q: int = 0
        d: int = 0
        for i in fs.find_missing(Date('2017-09-10'), Date('2019-05-25')):
            obj_path: RepoObjectPath = RepoObjectPath.from_uri(i, repo_format)
            if obj_path[0] == str(DatePeriodType.QUARTER):
                assert obj_path[-1] == 'master.idx'
                q += 1
            else:
                the_date: Date = obj_path.date()
                assert not the_date.is_weekend()
                assert the_date not in holidays_sample
                d += 1

        assert q == 7
        assert d == 350
 def test_get_object_failure(self, test_fs: tempfile.TemporaryDirectory,
                             repo_format: RepoFormat, obj_path: str):
     root: Path = Path(test_fs.name)
     fs: FileRepoFS = FileRepoFS(root, repo_format)
     obj: FileRepoObject = fs.get_object(obj_path)
     assert obj is None
Пример #8
0
def sink_fs(dir_empty: tempfile.TemporaryDirectory, repo_format: RepoFormat):
    return FileRepoFS(Path(dir_empty.name), repo_format)