def test_csv_header_simple(data): header = ["abc", "cde"] csv_string = data.draw(csv(header=header, lines=5)) records = csv2records(csv_string) extracted_header = list(records[0].keys()) assert extracted_header == header
def test_csv_dialect_tab(data): header = ["abc", "cde"] csv_string = data.draw(csv(header=header, lines=5, dialect="excel-tab")) records = csv2records(csv_string, delimiter="\t") extracted_header = list(records[0].keys()) assert extracted_header == header assert len(records) == 5
def test_csv_columns_seq(data): columns = [ st.text(min_size=1, max_size=100, alphabet=string.ascii_lowercase + string.ascii_uppercase + string.digits), st.integers(), st.floats(min_value=1.2, max_value=100.12) ] csv_string = data.draw(csv(columns=columns, lines=40)) records = csv2records(csv_string, has_header=False) detected_types = detect_types(records)[1] types = list(map(lambda x: x["type"], detected_types["types"])) assert len(records) == 40 assert types == ["text", "int", "float"]
def test_csv_columns_and_header_seq(data): columns = [ st.text(min_size=1, max_size=100, alphabet=string.ascii_lowercase + string.ascii_uppercase + string.digits), st.integers(), st.floats(min_value=1.2, max_value=100.12) ] header = ["x", "y", "z"] csv_string = data.draw(csv(header=header, columns=columns, lines=10)) records = csv2records(csv_string) detected_types = detect_types(records)[1] types = list(map(lambda x: x["type"], detected_types["types"])) assert types == ["text", "int", "float"] extracted_header = list(records[0].keys()) assert extracted_header == header
def test_csv_lines_fixed(data): lines = 10 csv_string = data.draw(csv(lines=lines)) records = csv2records(csv_string, has_header=False) assert len(records) == lines
def test_csv_header_property(data, header): header = list(set(header)) csv_string = data.draw(csv(header=header)) records = csv2records(csv_string) extracted_header = list(records[0].keys()) assert extracted_header == header
def test_csv_all_random(data): csv_string = data.draw(csv()) assert isinstance(csv_string, str)
def test_csv_dialect_none(data): header = ["abc", "cde"] csv_string = data.draw(csv(header=header, lines=5, dialect=None)) records = csv2records(csv_string) assert len(records) == 5
def test_csv_header_int(data, kwargs): csv_string = data.draw(csv(**kwargs)) records = csv2records(csv_string, has_header="header" in kwargs) extracted_header = list(records[0].keys()) assert len(extracted_header) == list(kwargs.values())[0]
def test_csv_parameter_fail(data, kwargs): with pytest.raises(InvalidArgument): data.draw(csv(**kwargs))