def test_init_ok(config):

    test_data_string = "some test data"

    configuration = Configuration(None,
                                  is_dict_config=True,
                                  dict_config=config)

    data_object = DataObject(configuration)

    requestor = CsvReader(configuration, "csv_reader")

    data_object.add(requestor, test_data_string, "test_data")

    writer = FileWriter(configuration, "recipe_file_writer")

    c = configuration.config_for_instance("recipe_file_writer")
    filename = c["dir"] + os.path.sep + c["filename"]

    # clean out test file location
    if os.path.exists(filename):
        os.remove(filename)

    data_object, terminate = writer.run(data_object)

    assert not terminate

    assert os.path.exists(filename)

    read_data = open(filename).read()

    assert test_data_string == read_data
def test_init_other_ok(config):
    config["implementation_config"]["writer_config"]["recipe_file_writer"][
        "filename"] = "unittest_file_writer.other"
    config["implementation_config"]["writer_config"]["recipe_file_writer"][
        "serializer"] = "other"

    test_data_string = "some test data"

    configuration = Configuration(None,
                                  is_dict_config=True,
                                  dict_config=config)

    data_object = DataObject(configuration)

    requestor = CsvReader(configuration, "csv_reader")

    data_object.add(requestor, test_data_string, "test_data")

    writer = Serializer(configuration, "recipe_file_writer")

    c = configuration.config_for_instance("recipe_file_writer")
    filename = c["dir"] + os.path.sep + c["filename"]

    # clean out test file location
    if os.path.exists(filename):
        os.remove(filename)

    with pytest.raises(Exception, match=r"Unsupported"):
        writer.run(data_object)
def test_init_ok(config):
    corpus = pd.read_csv("test/minimal.csv")

    configuration = Configuration(None,
                                  is_dict_config=True,
                                  dict_config=config)

    writer = CsvWriter(configuration, "recipe_csv_writer")

    data_object = DataObject(configuration)
    requestor = CsvReader(configuration, "csv_reader")
    data_object.add(requestor, key="test_data", data=corpus)

    c = configuration.config_for_instance(
        "recipe_csv_writer"
    )  # configuration.sec .writer_config['recipe_csv_writer']
    filename = c["dir"] + os.path.sep + c["filename"]

    # clean out test file location
    if os.path.exists(filename):
        os.remove(filename)

    writer.run(data_object)

    assert os.path.exists(filename)

    df = pd.read_csv(filename)

    assert corpus.equals(df)
def test_init_pickle_ok(config):
    config["implementation_config"]["writer_config"]["recipe_file_writer"][
        "filename"] = "unittest_file_writer.pickle"
    config["implementation_config"]["writer_config"]["recipe_file_writer"][
        "serializer"] = "pickle"

    test_data_string = "some test data"

    configuration = Configuration(None,
                                  is_dict_config=True,
                                  dict_config=config)

    data_object = DataObject(configuration)

    requestor = CsvReader(configuration, "csv_reader")

    data_object.add(requestor, test_data_string, "test_data")

    writer = Serializer(configuration, "recipe_file_writer")

    c = configuration.config_for_instance("recipe_file_writer")
    filename = c["dir"] + os.path.sep + c["filename"]

    # clean out test file location
    if os.path.exists(filename):
        os.remove(filename)

    data_object, terminate = writer.run(data_object)

    assert not terminate

    assert os.path.exists(filename)

    read_data = pickle.load(open(filename, "rb"))

    assert test_data_string == read_data