예제 #1
0
def test_mok_store_invalid_params(data_type, extension):
    """
    test storing data with invalid file format
    """
    moker = Mok(data_type=data_type)
    with pytest.raises(ValueError):
        moker.store(extension=extension,
                    domain=extension if data_type == "specifc" else None)
예제 #2
0
def test_mok_batch_invalid():
    """
    test generating random files fails with valueerror if
    data_type is invalid
    """
    moker = Mok(data_type="random")
    moker.data_type = "specific"
    with pytest.raises(ValueError):
        moker.store()
예제 #3
0
def test_mok_store_random_extension(
        domain,
        test_data_dir  # pylint: disable=redefined-outer-name
):
    """
    test storing data with invalid file format
    """
    moker = Mok(data_type="specific")
    file_path = moker.store(domain=domain, data_dir=test_data_dir)
    assert pathlib.Path(file_path).exists()
예제 #4
0
def test_mok_store_invalid_extension(
        domain,
        test_data_dir  # pylint: disable=redefined-outer-name
):
    """
    test storing data with invalid file format
    """
    moker = Mok(data_type="specific")
    with pytest.raises(ValueError):
        moker.store(domain=domain, data_dir=test_data_dir, extension="invalid")
예제 #5
0
def test_mok_store_no_file_name(
        domain,
        extension,
        test_data_dir  # pylint: disable=redefined-outer-name
):
    """
    test generating various domain specific datasets
    """
    moker = Mok(data_type="specific")
    assert not test_data_dir.joinpath(
        f"{moker.default_fn}.{extension}").exists()
    moker.store(data_dir=test_data_dir, extension=extension, domain=domain)
    assert test_data_dir.joinpath(f"{moker.default_fn}.{extension}").exists()
예제 #6
0
def test_mok_batch(num_files, test_data_dir):  # pylint: disable=redefined-outer-name
    """
    test generating random files in a batch
    """
    moker = Mok(data_type="random")
    file_paths = moker.batch(data_dir=str(test_data_dir), num_files=num_files)
    for file_path in file_paths:
        assert pathlib.Path(file_path).exists()
        assert pathlib.Path(file_path).suffix.replace(".", "") in [
            "json",
            "csv",
            "parquet",
            "xlsx",
        ]
예제 #7
0
def test_mok_batch_default_dir(num_files):
    """
    test generating random files in a batch
    """
    moker = Mok(data_type="random")
    file_paths = moker.batch(num_files=num_files)
    for file_path in file_paths:
        assert pathlib.Path(file_path).exists()
        assert pathlib.Path(file_path).suffix.replace(".", "") in [
            "json",
            "csv",
            "parquet",
            "xlsx",
        ]
    shutil.rmtree(moker.default_dir)
예제 #8
0
def test_mok_store_specific(
        domain,
        extension,
        test_data_dir,  # pylint: disable=redefined-outer-name
):
    """
    test generating various domain specific datasets
    """
    file_name = test_data_dir.joinpath(f"{domain}.{extension}")
    assert not file_name.exists()
    moker = Mok(data_type="specific")
    moker.store(
        file_name=str(file_name),
        data_dir=test_data_dir,
        extension=extension,
        domain=domain,
    )
    assert pathlib.Path(str(file_name) + f".{extension}").exists()
예제 #9
0
def test_mok_init_invalid(data_type):
    """
    test initializing data generator with invalid data types
    """
    with pytest.raises(ValueError):
        Mok(data_type=data_type)
예제 #10
0
def test_mok_init_valid(data_type):
    """
    test initializing data generator with valid data types
    """
    moker = Mok(data_type=data_type)
    assert moker.data_type == data_type