1#!/usr/bin/env python3 2# Copyright 2020 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""The unittest of factory_config_proto_converter.py""" 6 7import os 8import subprocess 9import tempfile 10import unittest 11 12import factory_config_proto_converter 13 14from chromiumos.config.test import fake_config 15 16THIS_DIR = os.path.dirname(__file__) 17 18PROGRAM_CONFIG_FILE = fake_config.FAKE_PROGRAM_CONFIG 19PROJECT_CONFIG_FILE = fake_config.FAKE_PROJECT_CONFIG 20 21 22def fakeConfig(): 23 return factory_config_proto_converter._MergeConfigs([ 24 factory_config_proto_converter._ReadConfig(PROGRAM_CONFIG_FILE), 25 factory_config_proto_converter._ReadConfig(PROJECT_CONFIG_FILE) 26 ]) 27 28 29class MainTest(unittest.TestCase): 30 31 def testFullTransform(self): 32 with tempfile.TemporaryDirectory() as tempdir: 33 output_file = os.path.join(tempdir, 'output') 34 factory_config_proto_converter.Main( 35 project_configs=[PROJECT_CONFIG_FILE], 36 program_config=PROGRAM_CONFIG_FILE, 37 output=output_file, 38 ) 39 40 expected_file = os.path.join(THIS_DIR, 'test_data/model_sku.json') 41 changed = subprocess.run(['diff', expected_file, output_file 42 ]).returncode != 0 43 44 regen_cmd = ('To regenerate the expected output, run:\n' 45 '\tcd payload_utils && ' 46 'python3 -m factory_config_proto_converter ' 47 '-c %s ' 48 '-p %s ' 49 '-o %s ' % 50 (PROJECT_CONFIG_FILE, PROGRAM_CONFIG_FILE, expected_file)) 51 52 if changed: 53 print(regen_cmd) 54 self.fail('Fake project transform does not match') 55 56 57if __name__ == '__main__': 58 unittest.main(module=__name__) 59