1#!/usr/bin/env python 2# 3# Copyright 2020 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16"""Tests for cvd_runtime_config class.""" 17 18import os 19import mock 20import six 21 22from acloud.internal.lib import cvd_runtime_config as cf_cfg 23from acloud.internal.lib import driver_test_lib 24 25 26class CvdRuntimeconfigTest(driver_test_lib.BaseDriverTest): 27 """Test CvdRuntimeConfig.""" 28 29 CF_RUNTIME_CONFIG = """ 30{"x_display" : ":20", 31 "x_res" : 720, 32 "y_res" : 1280, 33 "instances": { 34 "1":{ 35 "adb_ip_and_port": "127.0.0.1:6520", 36 "host_port": 6520, 37 "instance_dir": "/path-to-instance-dir", 38 "vnc_server_port": 6444 39 } 40 } 41} 42""" 43 44 # pylint: disable=protected-access 45 def testGetCuttlefishRuntimeConfig(self): 46 """Test GetCuttlefishRuntimeConfig.""" 47 # Should raise error when file does not exist. 48 self.Patch(os.path, "exists", return_value=False) 49 # Verify return data. 50 self.Patch(os.path, "exists", return_value=True) 51 expected_dict = {u'y_res': 1280, 52 u'x_res': 720, 53 u'x_display': u':20', 54 u'instances': 55 {u'1': 56 {u'adb_ip_and_port': u'127.0.0.1:6520', 57 u'host_port': 6520, 58 u'instance_dir': u'/path-to-instance-dir', 59 u'vnc_server_port': 6444} 60 }, 61 } 62 mock_open = mock.mock_open(read_data=self.CF_RUNTIME_CONFIG) 63 cf_cfg_path = "/fake-path/local-instance-1/fake.config" 64 with mock.patch.object(six.moves.builtins, "open", mock_open): 65 self.assertEqual(expected_dict, 66 cf_cfg.CvdRuntimeConfig(cf_cfg_path)._config_dict) 67