def testCSVPluginWritesBytesValuesCorrectly(self): pathspec = rdf_paths.PathSpec.OS(path="/żółta/gęśla/jaźń") values = { rdf_client.BufferReference: [ rdf_client.BufferReference(data=b"\xff\x00\xff", pathspec=pathspec), rdf_client.BufferReference(data=b"\xfa\xfb\xfc", pathspec=pathspec), ], } zip_fd, prefix = self.ProcessValuesToZip(values) manifest_path = "{}/MANIFEST".format(prefix) data_path = "{}/ExportedMatch/from_BufferReference.csv".format(prefix) self.assertCountEqual(zip_fd.namelist(), [manifest_path, data_path]) with zip_fd.open(data_path) as data: results = list(compat_csv.Reader(data.read().decode("utf-8"))) self.assertLen(results, 3) data_idx = results[0].index("data") self.assertEqual(results[1][data_idx], "ff00ff") self.assertEqual(results[2][data_idx], "fafbfc")
def testUnicode(self): reader = csv.Reader("wąwóz,źdźbło\ngrzęda,wątły\ndźwig,ścieżka") self.assertEqual(list(reader), [ ["wąwóz", "źdźbło"], ["grzęda", "wątły"], ["dźwig", "ścieżka"], ])
def testMultipleRows(self): reader = csv.Reader("foo,quux\nbar,norf\nbaz,thud") self.assertEqual(list(reader), [ ["foo", "quux"], ["bar", "norf"], ["baz", "thud"], ])
def testCSVPluginWritesUnicodeValuesCorrectly(self): zip_fd, prefix = self.ProcessValuesToZip({ rdf_client_fs.StatEntry: [ rdf_client_fs.StatEntry( pathspec=rdf_paths.PathSpec(path="/中国新闻网新闻中", pathtype="OS")) ] }) self.assertEqual( set(zip_fd.namelist()), set([ "%s/MANIFEST" % prefix, "%s/ExportedFile/from_StatEntry.csv" % prefix ])) data = zip_fd.open("%s/ExportedFile/from_StatEntry.csv" % prefix).read() parsed_output = list(compat_csv.Reader(data.decode("utf-8"))) self.assertLen(parsed_output, 2) urn_pos = parsed_output[0].index("urn") urn = parsed_output[1][urn_pos] self.assertEqual(urn, "aff4:/C.1000000000000000/fs/os/中国新闻网新闻中")
def testDefaultQuotechar(self): reader = csv.Reader("foo,\"bar, baz, quux\",norf,\"thud\"") self.assertEqual(list(reader), [["foo", "bar, baz, quux", "norf", "thud"]])
def testMultipleUsages(self): reader = csv.Reader("foo") self.assertEqual(list(reader), [["foo"]]) self.assertEqual(list(reader), [["foo"]])
def testCustomDelimiter(self): reader = csv.Reader("foo|bar|baz", delimiter="|") self.assertEqual(list(reader), [["foo", "bar", "baz"]])
def testSingleRow(self): reader = csv.Reader("foo,bar,baz") self.assertEqual(list(reader), [["foo", "bar", "baz"]])
def testEmpty(self): reader = csv.Reader("") self.assertEqual(list(reader), [])