예제 #1
0
def google_credentials_path():
    path = os.environ.get("GOOGLE_CREDENTIALS_PATH")
    if not path or not os.path.isfile(path):
        pytest.skip('Environment variable "GOOGLE_CREDENTIALS_PATH" is not available')
    elif not helpers.is_platform("linux") or sys.version_info < (3, 8):
        pytest.skip('Environment variable "GOOGLE_CREDENTIALS_PATH" is Linux/Python3.8')
    return path
import pytest
from frictionless import Package, Resource, helpers
from frictionless import FrictionlessException


IS_UNIX = not helpers.is_platform("windows")
BASEURL = "https://raw.githubusercontent.com/frictionlessdata/frictionless-py/master/%s"


# Metadata


@pytest.mark.vcr
def test_package_external_profile():
    profile = "frictionless/assets/profiles/package/general.json"
    resource = Resource(name="table", path="data/table.csv")
    package = Package(resources=[resource], profile=profile)
    assert package.metadata_valid


@pytest.mark.vcr
def test_package_external_profile_invalid_local():
    profile = "data/profiles/camtrap.json"
    resource = Resource(name="table", path="data/table.csv")
    package = Package(resources=[resource], profile=profile)
    assert len(package.metadata_errors) == 5
    for error in package.metadata_errors:
        assert "required" in error.message


@pytest.mark.vcr
예제 #3
0
import pytest
import datetime
from frictionless import Package, Resource, FrictionlessException, helpers
from frictionless.plugins.spss import SpssStorage

# Parser


@pytest.mark.skipif(helpers.is_platform("macos"),
                    reason="It doesn't work for MacOS")
def test_spss_parser(tmpdir):

    # Write
    source = Resource("data/table.csv")
    target = Resource(str(tmpdir.join("table.sav")))
    source.write(target)

    # Read
    with target:
        assert target.header == ["id", "name"]
        assert target.read_rows() == [
            {
                "id": 1,
                "name": "english"
            },
            {
                "id": 2,
                "name": "中国人"
            },
        ]
예제 #4
0
import json
import yaml
import pytest
from typer.testing import CliRunner
from frictionless import program, extract, helpers

runner = CliRunner()


# General


@pytest.mark.skipif(helpers.is_platform("windows"), reason="It doesn't work for Windows")
def test_extract():
    result = runner.invoke(program, "extract data/table.csv")
    assert result.exit_code == 0
    assert result.stdout.count("data: data/table.csv")
    assert result.stdout.count("id  name")
    assert result.stdout.count("1  english")
    assert result.stdout.count("2  中国人")


def test_extract_header_rows():
    result = runner.invoke(program, "extract data/table.csv --json --header-rows '1,2'")
    assert result.exit_code == 0
    assert json.loads(result.stdout) == extract(
        "data/table.csv", layout={"headerRows": [1, 2]}
    )


def test_extract_header_join():
예제 #5
0
import pytest
from frictionless import describe, helpers

# General


@pytest.mark.skipif(helpers.is_platform("windows"),
                    reason="It doesn't work for Windows")
def test_describe_package():
    package = describe("data/chunk*.csv")
    assert package.metadata_valid
    assert package == {
        "profile":
        "data-package",
        "resources": [
            {
                "path": "data/chunk1.csv",
                "profile": "tabular-data-resource",
                "name": "chunk1",
                "scheme": "file",
                "format": "csv",
                "hashing": "md5",
                "encoding": "utf-8",
                "compression": "no",
                "compressionPath": "",
                "control": {
                    "newline": ""
                },
                "dialect": {},
                "query": {},
                "schema": {
import sys
import pytest
import datetime
from frictionless import Package, Resource, helpers

IS_MACOS = helpers.is_platform("macos")

# General


@pytest.mark.skipif(sys.version_info >= (3, 10),
                    reason="Not supported Python3.10")
def test_spss_parser_write(tmpdir):
    source = Resource("data/table.csv")
    if not IS_MACOS:
        target = source.write(str(tmpdir.join("table.sav")))
        with target:
            assert target.header == ["id", "name"]
            assert target.read_rows() == [
                {
                    "id": 1,
                    "name": "english"
                },
                {
                    "id": 2,
                    "name": "中国人"
                },
            ]


@pytest.mark.skipif(sys.version_info >= (3, 10),