def parse(device: str, revision: str, area: str, output: click.Path, binary: click.File, show_calc: bool, show_diff: bool) -> None: """Parse binary a extract configuration.""" pfr_obj = _get_pfr_class(area)(device=device, revision=revision) data = binary.read() # type: ignore parsed = pfr_obj.parse(data, exclude_computed=False) if show_diff: parsed = dict_diff( pfr_obj.generate_config(exclude_computed=not show_calc), parsed) json_data = json.dumps(parsed, indent=2) _store_output(json_data, output)
def test_nested_diff(): """Simple test of dictionary compare with nested dictionaries.""" main = { "BOOT_CFG": { "DEFAULT_ISP_MODE": "0b000", "BOOT_SPEED": "0b00", "BOOT_FAILURE_PIN": "0x0" }, "SPI_FLASH_CFG": "0b0_0000", "USB_ID": { "USB_VENDOR_ID": "0x00", "USB_PRODUCT_ID": "0x00" }, "CUSTOMER_DEFINED0": "0x0000", "CUSTOMER_DEFINED1": "0x0000", "CUSTOMER_DEFINED2": "0x0000", "CUSTOMER_DEFINED3": "0x0000", } mod = { "BOOT_CFG": { "DEFAULT_ISP_MODE": "0b000", "BOOT_SPEED": "0b11", "BOOT_FAILURE_PIN": "0x0" }, "CUSTOMER_DEFINED0": "0x0000", "CUSTOMER_DEFINED1": "0x0000", "CUSTOMER_DEFINED2": "0xABCD", "CUSTOMER_DEFINED3": "0xEF01", "ThisOneDoesn'tExists": "0x00", } expect = { "BOOT_CFG": { "BOOT_SPEED": "0b11" }, "CUSTOMER_DEFINED2": "0xABCD", "CUSTOMER_DEFINED3": "0xEF01", } assert expect == dict_diff(main, mod)
def test_simple_diff_strings(): """Simple test of dictionary compare with integers.""" main = {"a": "0b00", "b": "Hello", "c": "Good Morning"} mod = {"b": "Cao", "c": "Good Morning"} assert dict_diff(main, mod) == {"b": "Cao"}
def test_simple_diff(): """Simple test of dictionary compare with integers.""" main = {"a": "0b00", "b": "0b01"} mod = {"b": "0b11"} assert dict_diff(main, mod) == {"b": "0b11"}
def test_simle_diff(): main = {'a': '0b00', 'b': '0b01'} mod = {'b': '0b11'} assert dict_diff(main, mod) == {'b': '0b11'}