Exemplo n.º 1
0
def test_library_properties_parser():
    # Base
    contents = """
name=TestPackage
version=1.2.3
author=SomeAuthor <info AT author.com>
sentence=This is Arduino library
customField=Custom Value
depends=First Library (=2.0.0), Second Library (>=1.2.0), Third
"""
    raw_data = parser.LibraryPropertiesManifestParser(contents).as_dict()
    raw_data["dependencies"] = sorted(raw_data["dependencies"],
                                      key=lambda a: a["name"])
    assert not jsondiff.diff(
        raw_data,
        {
            "name":
            "TestPackage",
            "version":
            "1.2.3",
            "description":
            "This is Arduino library",
            "sentence":
            "This is Arduino library",
            "platforms": ["*"],
            "frameworks": ["arduino"],
            "export": {
                "exclude":
                ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"]
            },
            "authors": [{
                "email": "*****@*****.**",
                "name": "SomeAuthor"
            }],
            "keywords": ["uncategorized"],
            "customField":
            "Custom Value",
            "depends":
            "First Library (=2.0.0), Second Library (>=1.2.0), Third",
            "dependencies": [
                {
                    "name": "First Library",
                    "version": "=2.0.0",
                    "frameworks": ["arduino"],
                },
                {
                    "name": "Second Library",
                    "version": ">=1.2.0",
                    "frameworks": ["arduino"],
                },
                {
                    "name": "Third",
                    "frameworks": ["arduino"]
                },
            ],
        },
    )

    # Platforms ALL
    data = parser.LibraryPropertiesManifestParser("architectures=*\n" +
                                                  contents).as_dict()
    assert data["platforms"] == ["*"]

    # Platforms specific
    data = parser.LibraryPropertiesManifestParser(
        "architectures=avr, esp32\n" + contents).as_dict()
    assert data["platforms"] == ["atmelavr", "espressif32"]

    # Remote URL
    data = parser.LibraryPropertiesManifestParser(
        contents,
        remote_url=(
            "https://raw.githubusercontent.com/username/reponame/master/"
            "libraries/TestPackage/library.properties"),
    ).as_dict()
    assert data["export"] == {
        "exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"],
        "include": ["libraries/TestPackage"],
    }
    assert data["repository"] == {
        "url": "https://github.com/username/reponame.git",
        "type": "git",
    }

    # Home page
    data = parser.LibraryPropertiesManifestParser(
        "url=https://github.com/username/reponame.git\n" + contents).as_dict()
    assert data["repository"] == {
        "type": "git",
        "url": "https://github.com/username/reponame.git",
    }

    # Author + Maintainer
    data = parser.LibraryPropertiesManifestParser("""
author=Rocket Scream Electronics
maintainer=Rocket Scream Electronics
""").as_dict()
    assert data["authors"] == [{
        "name": "Rocket Scream Electronics",
        "maintainer": True
    }]
Exemplo n.º 2
0
def test_library_properties_parser():
    # Base
    contents = """
name=TestPackage
version=1.2.3
author=SomeAuthor <info AT author.com>
sentence=This is Arduino library
customField=Custom Value
"""
    mp = parser.LibraryPropertiesManifestParser(contents)
    assert not jsondiff.diff(
        mp.as_dict(),
        {
            "name": "TestPackage",
            "version": "1.2.3",
            "description": "This is Arduino library",
            "sentence": "This is Arduino library",
            "platforms": ["*"],
            "frameworks": ["arduino"],
            "export": {
                "exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"]
            },
            "authors": [{"email": "*****@*****.**", "name": "SomeAuthor"}],
            "keywords": ["uncategorized"],
            "customField": "Custom Value",
        },
    )

    # Platforms ALL
    data = parser.LibraryPropertiesManifestParser(
        "architectures=*\n" + contents
    ).as_dict()
    assert data["platforms"] == ["*"]
    # Platforms specific
    data = parser.LibraryPropertiesManifestParser(
        "architectures=avr, esp32\n" + contents
    ).as_dict()
    assert data["platforms"] == ["atmelavr", "espressif32"]

    # Remote URL
    data = parser.LibraryPropertiesManifestParser(
        contents,
        remote_url=(
            "https://raw.githubusercontent.com/username/reponame/master/"
            "libraries/TestPackage/library.properties"
        ),
    ).as_dict()
    assert data["export"] == {
        "exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"],
        "include": ["libraries/TestPackage"],
    }
    assert data["repository"] == {
        "url": "https://github.com/username/reponame",
        "type": "git",
    }

    # Hope page
    data = parser.LibraryPropertiesManifestParser(
        "url=https://github.com/username/reponame.git\n" + contents
    ).as_dict()
    assert data["repository"] == {
        "type": "git",
        "url": "https://github.com/username/reponame.git",
    }