当前位置: 首页>>代码示例>>Python>>正文


Python JournalFixtureFactory.csv_headers方法代码示例

本文整理汇总了Python中doajtest.fixtures.JournalFixtureFactory.csv_headers方法的典型用法代码示例。如果您正苦于以下问题:Python JournalFixtureFactory.csv_headers方法的具体用法?Python JournalFixtureFactory.csv_headers怎么用?Python JournalFixtureFactory.csv_headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在doajtest.fixtures.JournalFixtureFactory的用法示例。


在下文中一共展示了JournalFixtureFactory.csv_headers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_journal_csv

# 需要导入模块: from doajtest.fixtures import JournalFixtureFactory [as 别名]
# 或者: from doajtest.fixtures.JournalFixtureFactory import csv_headers [as 别名]

#.........这里部分代码省略.........

                comparisons[issns[0]]["article_count"] = 2
                comparisons[issns[0]]["article_latest"] = "2019-0{i}-02T00:00:00Z".format(i=i + 1)

        if journals_no_issn_count > 0:
            noissns = [models.Journal(**s) for s in JournalFixtureFactory.make_many_journal_sources(count=journals_no_issn_count, in_doaj=True)]
            for i in range(len(noissns)):
                noissn = noissns[i]
                bj = noissn.bibjson()
                bj.remove_identifiers(idtype=bj.P_ISSN)
                bj.remove_identifiers(idtype=bj.E_ISSN)
                noissn.set_id("no_issn_{i}".format(i=i))
            journals += noissns

        if not_in_doaj_count > 0:
            nots = [models.Journal(**s) for s in JournalFixtureFactory.make_many_journal_sources(count=not_in_doaj_count, in_doaj=False)]
            for i in range(len(nots)):
                n = nots[i]
                n.set_id("not_in_doaj_{i}".format(i=i))
            journals += nots

        jids = []
        for i in range(len(journals)):
            journals[i].save()
            jids.append((journals[i].id, journals[i].last_updated))

        aids = []
        for i in range(len(articles)):
            articles[i].save()
            aids.append((articles[i].id, articles[i].last_updated))

        if prune:
            self.localStore.store(self.container_id, "journalcsv__doaj_20180101_0000_utf8.csv", source_stream=StringIO("test1"))
            self.localStore.store(self.container_id, "journalcsv__doaj_20180601_0000_utf8.csv", source_stream=StringIO("test2"))
            self.localStore.store(self.container_id, "journalcsv__doaj_20190101_0000_utf8.csv", source_stream=StringIO("test3"))

        models.Journal.blockall(jids)
        models.Article.blockall(aids)

        ###########################################################
        # Execution

        if raises is not None:
            with self.assertRaises(raises):
                self.svc.csv(prune)

                tempFiles = self.tmpStore.list(self.container_id)
                assert len(tempFiles) == 0
        else:
            url, action_register = self.svc.csv(prune)
            assert url is not None

            csv_info = models.cache.Cache.get_latest_csv()
            assert csv_info.get("url") == url

            filenames = self.localStore.list(self.container_id)
            if prune:
                assert len(filenames) == 2
                assert "journalcsv__doaj_20180101_0000_utf8.csv" not in filenames
                assert "journalcsv__doaj_20180601_0000_utf8.csv" not in filenames
                assert "journalcsv__doaj_20190101_0000_utf8.csv" in filenames
            else:
                assert len(filenames) == 1

            latest = None
            for fn in filenames:
                if fn != "journalcsv__doaj_20190101_0000_utf8.csv":
                    latest = fn
                    break

            handle = self.localStore.get(self.container_id, latest, encoding="utf-8")
            reader = clcsv.UnicodeReader(handle)
            rows = [r for r in reader]

            if len(comparisons) > 0:
                expected_headers = JournalFixtureFactory.csv_headers()
                for i in range(len(expected_headers)):
                    h = expected_headers[i]
                    if h != rows[0][i]:
                        print("{x} - {y}".format(x=h, y=rows[0][i]))
                assert rows[0] == expected_headers

                assert len(rows) == journal_count + 1

                for i in range(1, len(rows)):
                    row = rows[i]
                    alt_title = row[2]
                    issn = row[3]
                    eissn = row[4]
                    article_count = int(row[55])
                    article_latest = row[56]

                    assert alt_title == u"Заглавие на журнала"
                    assert issn in comparisons[issn]["issns"]
                    assert eissn in comparisons[issn]["issns"]
                    assert article_count == comparisons[issn]["article_count"], (article_count, comparisons[issn]["article_count"])
                    assert article_latest == comparisons[issn]["article_latest"]

            else:
                assert len(rows) == 0
开发者ID:DOAJ,项目名称:doaj,代码行数:104,代码来源:test_bll_journal_csv.py


注:本文中的doajtest.fixtures.JournalFixtureFactory.csv_headers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。