gp2040ce-binary-tools/tests/test_package.py
Brian S. Stephan b3f6f86950
ship precompiled protobuf files for convenience
current libraries seem to have problems on Windows with thinking files
are duplicated when they are not, making it impossible to compile .proto
files at runtime in this tool on that platform. this adds a fallback of
using shipped, precompiled files in the package. I was already intending
on providing this as an option anyway, so might as well start doing it
now.

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2024-01-09 09:40:07 -06:00

49 lines
1.5 KiB
Python

"""Test high level package capabilities.
SPDX-FileCopyrightText: © 2023 Brian S. Stephan <bss@incorporeal.org>
SPDX-License-Identifier: MIT
"""
import os
import sys
from gp2040ce_bintools import get_config_pb2
HERE = os.path.dirname(os.path.abspath(__file__))
def test_get_config_pb2_compile():
"""Without any precompiled files on the path, test we can read proto files and compile them."""
# append to path as -P would
proto_path = os.path.join(HERE, 'test-files', 'proto-files')
sys.path.append(proto_path)
# let grpc tools compile the proto files on demand and give us the module
config_pb2 = get_config_pb2()
_ = config_pb2.Config()
# clean up the path and unload config_pb2
sys.path.pop()
sys.path.pop()
del sys.modules['config_pb2']
def test_get_config_pb2_exception():
"""Without any precompiled files or proto files on the path, test we DO NOT raise an exception."""
# this used to raise ModuleNotFoundError, but with our snapshot included now,
# we should always have a config to import
_ = get_config_pb2()
def test_get_config_pb2_precompile():
"""Test we can import precompiled protobuf files."""
proto_path = os.path.join(HERE, 'test-files', 'pb2-files')
sys.path.append(proto_path)
# let grpc tools import the proto files normally
config_pb2 = get_config_pb2()
_ = config_pb2.Config()
# clean up the path and unload config_pb2
sys.path.pop()
del sys.modules['config_pb2']