def test_simple_multiprocessing(self):
        r1 = list(XmlReader.read_xml(gzip.open(
            resource_filename(__name__, "Wikidata-Q1.xml.gz")), 1))
        r4 = list(XmlReader.read_xml(gzip.open(
            resource_filename(__name__, "Wikidata-Q1.xml.gz")), 4))

        assert 1 == len(r1)
        assert r1 == r4
    def test_multiprocessing(self):
        file_name = "Wikidata-20131129161111.xml.gz"
        r1 = list(XmlReader.read_xml(gzip.open(
            resource_filename(__name__, file_name)), 1))
        r4 = list(XmlReader.read_xml(gzip.open(
            resource_filename(__name__, file_name)), 4))

        assert 87 == len(r1)
        assert r1 == r4
예제 #3
0
    def test_multiprocessing(self):
        file_name = "Wikidata-20131129161111.xml.gz"
        r1 = list(
            XmlReader.read_xml(
                gzip.open(resource_filename(__name__, file_name)), 1))
        r4 = list(
            XmlReader.read_xml(
                gzip.open(resource_filename(__name__, file_name)), 4))

        assert 87 == len(r1)
        assert r1 == r4
예제 #4
0
    def test_simple_multiprocessing(self):
        r1 = list(
            XmlReader.read_xml(
                gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz")),
                1))
        r4 = list(
            XmlReader.read_xml(
                gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz")),
                4))

        self.assertThat(r1, HasLength(1))
        self.assertThat(r4, Equals(r1))
예제 #5
0
    def test_simple_multiprocessing(self):
        r1 = list(
            XmlReader.read_xml(
                gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz")),
                1))
        r4 = list(
            XmlReader.read_xml(
                gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz")),
                4))

        assert 1 == len(r1)
        assert r1 == r4
예제 #6
0
    def test_write_big_csv(self):
        out = StringIO()
        f = resource_filename(__name__, "Wikidata-20131129161111.xml.gz")
        xml = XmlReader.read_xml(gzip.open(f))
        CsvWriter.write_csv(xml, out)

        out.seek(0)
        self.assertThat(len(out.readlines()), Equals(5627))
예제 #7
0
    def test_write_big_csv(self):
        out = StringIO()
        f = resource_filename(__name__, "Wikidata-20131129161111.xml.gz")
        xml = XmlReader.read_xml(gzip.open(f))
        CsvWriter.write_csv(xml, out)

        out.seek(0)
        self.assertThat(len(out.readlines()), Equals(3679))
예제 #8
0
    def test_updated_dump(self):
        with gzip.open(resource_filename(__name__, "Wikidata-Q9351.xml.gz"), "r") as f:
            result = list(XmlReader.read_xml(f))

        self.assertThat(len(result), Equals(1))
        q9351 = result[0]
        self.assertThat(q9351.title, Equals("Q9351"))
        self.assertThat(q9351.claims, Contains(Claim(156, "wikibase-entityid", "Q1647331")))
        self.assertThat(q9351.claims, Contains(Claim(1112, "quantity", "+25")))
예제 #9
0
    def test_updated_dump(self):
        file_path = resource_filename(__name__, "Wikidata-Q9351.xml.gz")
        with gzip.open(file_path, "r") as f:
            result = list(XmlReader.read_xml(f))

        assert 1 == len(result)
        q9351 = result[0]
        assert 'Q9351' == q9351.title
        assert (Claim(Snak(156, "wikibase-item", "Q1647331")) in q9351.claims)
        assert Claim(Snak(1112, "quantity", "+25")) in q9351.claims
    def test_updated_dump(self):
        file_path = resource_filename(__name__, "Wikidata-Q9351.xml.gz")
        with gzip.open(file_path, "r") as f:
            result = list(XmlReader.read_xml(f))

        assert 1 == len(result)
        q9351 = result[0]
        assert 'Q9351' == q9351.title
        assert (Claim(Snak(156, "wikibase-item", "Q1647331")) in
                q9351.claims)
        assert Claim(Snak(1112, "quantity", "+25")) in q9351.claims
예제 #11
0
    def test_updated_dump(self):
        with gzip.open(resource_filename(__name__, "Wikidata-Q9351.xml.gz"),
                       "r") as f:
            result = list(XmlReader.read_xml(f))

        self.assertThat(len(result), Equals(1))
        q9351 = result[0]
        self.assertThat(q9351.title, Equals("Q9351"))
        self.assertThat(q9351.claims,
                        Contains(Claim(156, "wikibase-entityid", "Q1647331")))
        self.assertThat(q9351.claims, Contains(Claim(1112, "quantity", "+25")))
예제 #12
0
    def test_universe(self):
        file_path = resource_filename(__name__, "Wikidata-Q1.xml.gz")
        with gzip.open(file_path, "r") as f:
            result = list(XmlReader.read_xml(f))
        assert 1 == len(result)
        q1 = result[0]

        assert "Q1" == q1.title
        assert (Claim(Snak(373, "string", "Universe"), [],
                      [Snak(143, "wikibase-item", "Q328")]) in q1.claims)
        assert Claim(Snak(31, "wikibase-item", "Q223557")) in q1.claims
        assert Claim(Snak(31, "wikibase-item", "Q1088088")) in q1.claims
        assert (Claim(Snak(361, "wikibase-item", "Q3327819"),
                      [Snak(31, "wikibase-item", "Q41719")], []) in q1.claims)
    def test_universe(self):
        file_path = resource_filename(__name__, "Wikidata-Q1.xml.gz")
        with gzip.open(file_path, "r") as f:
            result = list(XmlReader.read_xml(f))
        assert 1 == len(result)
        q1 = result[0]

        assert "Q1" == q1.title
        assert (Claim(Snak(373, "string", "Universe"), [],
                      [Snak(143, "wikibase-item", "Q328")]) in
                q1.claims)
        assert Claim(Snak(31, "wikibase-item", "Q223557")) in q1.claims
        assert Claim(Snak(31, "wikibase-item", "Q1088088")) in q1.claims
        assert (Claim(Snak(361, "wikibase-item", "Q3327819"),
                      [Snak(31, "wikibase-item", "Q41719")], []) in
                q1.claims)
예제 #14
0
 def setUp(self):
     TestCase.setUp(self)
     with gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz"), "r") as f:
         self.result = list(XmlReader.read_xml(f))
예제 #15
0
 def setUp(self):
     TestCase.setUp(self)
     with gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz"),
                    "r") as f:
         self.result = list(XmlReader.read_xml(f))
 def test_special_cases(self):
     assert Entity("Q1", []) == XmlReader._process_json(("Q1", "{}"))
     data = '{"claims":[{"m":["value","","bad"], "refs":[],"q":[]}]}'
     assert Entity("Q1", []) == XmlReader._process_json(("Q1", data))
     data = '{"claims":[{"m":["value","","unknown"], "refs":[],"q":[]}]}'
     assert Entity("Q1", []) == XmlReader._process_json(("Q1", data))
예제 #17
0
 def test_special_cases(self):
     self.assertThat(XmlReader._process_json(("Q1", "{}")), Equals(Entity("Q1", [])))
     self.assertThat(XmlReader._process_json(("Q1", '{"claims":[{"m":["value","","bad"], "refs":[],"q":[]}]}')),
                     Equals(Entity("Q1", [])))
     self.assertThat(XmlReader._process_json(("Q1", '{"claims":[{"m":["value","","unknown"], "refs":[],"q":[]}]}')),
                     Equals(Entity("Q1", [])))
예제 #18
0
 def test_special_cases(self):
     assert Entity("Q1", []) == XmlReader._process_json(("Q1", "{}"))
     data = '{"claims":[{"m":["value","","bad"], "refs":[],"q":[]}]}'
     assert Entity("Q1", []) == XmlReader._process_json(("Q1", data))
     data = '{"claims":[{"m":["value","","unknown"], "refs":[],"q":[]}]}'
     assert Entity("Q1", []) == XmlReader._process_json(("Q1", data))
예제 #19
0
    def test_multiprocessing(self):
        r1 = list(XmlReader.read_xml(gzip.open(resource_filename(__name__, "Wikidata-20131129161111.xml.gz")), 1))
        r4 = list(XmlReader.read_xml(gzip.open(resource_filename(__name__, "Wikidata-20131129161111.xml.gz")), 4))

        self.assertThat(r1, HasLength(87))
        self.assertThat(r4, Equals(r1))
예제 #20
0
 def test_universe(self):
     with gzip.open(resource_filename(__name__, "Wikidata-Q1.xml.gz"), "r") as f:
         result = list(XmlReader.read_xml(f))
     self.assert_universe(result)