當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。