예제 #1
0
def test_extract_metadata_byte_code():
    """
    Ensure the __version__ is correctly extracted from the bytecode ".mpy"
    file. Version in test_module is 0.9.2
    """
    result = circup.extract_metadata("tests/test_module.mpy")
    assert result["__version__"] == "0.9.2"
    assert result["mpy"] is True
예제 #2
0
def test_extract_metadata_byte_code_v7():
    """
    Ensure the __version__ is correctly extracted from the bytecode ".mpy"
    file generated from Circuitpython >= 7. Version in local_module_cp7 is 1.2.3
    """
    result = circup.extract_metadata("tests/local_module_cp7.mpy")
    assert result["__version__"] == "1.2.3"
    assert result["mpy"] is True
    assert result["compatibility"] == ("7.0.0-alpha.1", None)
예제 #3
0
def test_extract_metadata_byte_code_v6():
    """
    Ensure the __version__ is correctly extracted from the bytecode ".mpy"
    file generated from Circuitpython < 7. Version in test_module is 0.9.2
    """
    result = circup.extract_metadata("tests/test_module.mpy")
    assert result["__version__"] == "0.9.2"
    assert result["mpy"] is True
    assert result["compatibility"] == (None, "7.0.0-alpha.1")
예제 #4
0
def test_extract_metadata_python():
    """
    Ensure the dunder objects assigned in code are extracted into a Python
    dictionary representing such metadata.
    """
    code = ("# A comment\n"
            '__version__ = "1.1.4"\n'
            '__repo__ = "https://github.com/adafruit/SomeLibrary.git"\n'
            'print("Hello, world!")\n')
    path = "foo.py"
    with mock.patch("builtins.open",
                    mock.mock_open(read_data=code)) as mock_open:
        result = circup.extract_metadata(path)
        mock_open.assert_called_once_with(path, encoding="utf-8")
    assert len(result) == 3
    assert result["__version__"] == "1.1.4"
    assert result["__repo__"] == "https://github.com/adafruit/SomeLibrary.git"
    assert result["mpy"] is False