From 654bebdeb66930def196d57c247efd43296c8683 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 7 Jul 2023 20:21:58 -0500 Subject: [PATCH] test an invocation of dump-config --- tests/test_commands.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index fe40815..2f5607a 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,10 +1,28 @@ """Test our tools themselves to make sure they adhere to certain flags.""" import json import os +import sys import unittest.mock as mock from subprocess import run +from decorator import decorator + from gp2040ce_bintools import __version__ +from gp2040ce_bintools.storage import get_config_from_file + +HERE = os.path.dirname(os.path.abspath(__file__)) + + +@decorator +def with_pb2s(test, *args, **kwargs): + """Wrap a test with precompiled pb2 files on the path.""" + proto_path = os.path.join(HERE, 'test-files', 'pb2-files') + sys.path.append(proto_path) + + test(*args, **kwargs) + + sys.path.pop() + del sys.modules['config_pb2'] def test_version_flag(): @@ -31,6 +49,17 @@ def test_concatenate_invocation(tmpdir): assert out[2088960:2097152] == storage +@with_pb2s +def test_dump_config_invocation(tmpdir, storage_dump, config_binary): + """Test that dumping a config to file works.""" + out_filename = os.path.join(tmpdir, 'out.bin') + with mock.patch('gp2040ce_bintools.pico.get_bootsel_endpoints', return_value=(mock.MagicMock(), mock.MagicMock())): + with mock.patch('gp2040ce_bintools.pico.read', return_value=storage_dump): + run(['dump-config', '-P', 'tests/test-files/proto-files', '--filename', out_filename]) + new_config = get_config_from_file(out_filename) + assert new_config.boardVersion == "v0.7.2" + + def test_storage_dump_invocation(): """Test that a normal invocation against a dump works.""" result = run(['visualize-storage', '-P', 'tests/test-files/proto-files',