示例#1
0
    def test_ignore_comments(self):
        csv = u"# top comment\na,b\n# any random comment\nc,d"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(["a", "b"], ["c", "d"])))
示例#2
0
    def test_ignore_values_in_comments_column(self):
        csv = u"a,comment,b\nc,d,e"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(["a", "b"], ["c", "e"])))
示例#3
0
    def test_ignore_when_empty_row(self):
        csv = u"a,b\n,\nc,d"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(["a", "b"], ["c", "d"])))
示例#4
0
    def test_accept_when_some_values_empty(self):
        csv = u"a,b\n,\nc,d\nc,"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(["a", "b"], ["c", "d"], ["c", ""])))
示例#5
0
    def test_parse_utf8_data(self):
        csv = u"a,b\nà,ù"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, contains(contains(["a", "b"], [u"à", u"ù"])))
示例#6
0
    def test_accept_csv_with_CRLF_as_line_separator(self):
        csv = u"prop1,prop2\r\nvalue 1,value 2"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(["prop1", "prop2"], ["value 1", "value 2"])))
示例#7
0
    def test_error_when_input_is_not_utf8(self):
        csv = u"a,b\nà,ù"

        csv_stream = _string_io(csv, "iso-8859-1")

        self.assertRaises(ParseError,
                          lambda csv_stream: _traverse(parse_csv(csv_stream)),
                          csv_stream)
示例#8
0
    def test_error_when_input_is_not_utf8(self):
        csv = u"a,b\nà,ù"

        csv_stream = _string_io(csv, "iso-8859-1")

        self.assertRaises(ParseError,
                          lambda csv_stream: _traverse(parse_csv(csv_stream)),
                          csv_stream)
示例#9
0
    def test_preserve_newlines_in_quoted_values(self):
        csv = u'prop1,prop2\nvalue,"value\nwith newline"'

        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(["prop1", "prop2"], ["value", "value\nwith newline"])))
示例#10
0
    def test_accept_csv_with_CR_as_line_separator(self):
        csv = u"prop1,prop2\rvalue 1,value 2"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(
            ["prop1", "prop2"],
            ["value 1", "value 2"],
        )))
示例#11
0
    def test_ignore_values_in_comments_column(self):
        csv = u"a,comment,b\nc,d,e"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(
            ["a", "b"],
            ["c", "e"],
        )))
示例#12
0
    def test_parse_csv(self):
        csv_stream = _string_io("a,b\nx,y\nq,w")

        data = parse_csv(csv_stream)

        assert_that(data, contains(contains(
            ["a", "b"],
            ["x", "y"],
            ["q", "w"],
        )))
示例#13
0
    def test_parse_utf8_data(self):
        csv = u"a,b\nà,ù"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, contains(contains(
            ["a", "b"],
            [u"à", u"ù"],
        )))
示例#14
0
    def test_ignore_comments(self):
        csv = u"# top comment\na,b\n# any random comment\nc,d"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(
            ["a", "b"],
            ["c", "d"],
        )))
示例#15
0
    def test_ignore_when_empty_row(self):
        csv = u"a,b\n,\nc,d"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(
            ["a", "b"],
            ["c", "d"],
        )))
示例#16
0
    def test_parse_csv(self):
        csv_stream = _string_io("a,b\nx,y\nq,w")

        data = parse_csv(csv_stream)

        assert_that(data, contains(contains(
            ["a", "b"],
            ["x", "y"],
            ["q", "w"],
        )))
示例#17
0
    def test_accept_when_some_values_empty(self):
        csv = u"a,b\n,\nc,d\nc,"
        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(
            ["a", "b"],
            ["c", "d"],
            ["c", ""],
        )))
示例#18
0
    def test_preserve_newlines_in_quoted_values(self):
        csv = u"prop1,prop2\nvalue,\"value\nwith newline\""

        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        assert_that(data, only_contains(only_contains(
            ["prop1", "prop2"],
            ["value", "value\nwith newline"],
        )))
    def test_parsing_numbers_in_cells(self):
        csv = u"int,float,string\n12,12.1,a string"

        csv_stream = _string_io(csv, "utf-8")

        data = parse_csv(csv_stream)

        print(list(data[0]))
        assert_that(data, only_contains(only_contains(
            ["int", "float", "string"],
            [12, 12.1, "a string"],
        )))
示例#20
0
    def test_parse_empty_csv(self):
        csv_stream = _string_io("")

        data = _traverse(parse_csv(csv_stream))

        assert_that(data, is_([[]]))
示例#21
0
    def test_parse_empty_csv(self):
        csv_stream = _string_io("")

        data = _traverse(parse_csv(csv_stream))

        assert_that(data, is_([[]]))