1#!/usr/bin/env python 2# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# pylint: disable-msg=C0111 7 8import unittest 9import cellular 10import labconfig 11# Use the same import line to keep this global on the same key 12from autotest_lib.client.cros.cellular import labconfig_data 13 14 15TEST_CELL = { 16 'duts': [ 17 { 18 'address': '1.2.3.4', 19 'name': 'one_two_three_four', 20 'technologies': ['CDMA_2000'], 21 'rf_switch_port': 0 22 }, 23 { 24 'address': '5.6.7.8', 25 'name': 'five_six_seven_eight', 26 'technologies': ['GPRS', 'EGPRS'], 27 }, 28 ], 29 'rf_switch': { 30 'type': 'ether_io', 31 'address': '172.31.206.172', 32 } 33 } 34 35class TestLabConfig(unittest.TestCase): 36 def setUp(self): 37 # Monkey-patch in our test cell 38 labconfig_data.CELLS['test'] = TEST_CELL 39 40 def test_get_present_cell(self): 41 c = labconfig.Configuration(['--cell', 'test']) 42 43 def test_get_missing_cell(self): 44 self.assertRaises(labconfig.LabConfigError, 45 labconfig.Configuration, ['--cell', 'NOT_PRESENT']) 46 47 def test_get_dut(self): 48 c = labconfig.Configuration(['--cell', 'test']) 49 m = c._get_dut('1.2.3.4') 50 self.assertEqual('one_two_three_four', m['name']) 51 52 m = c._get_dut('one_two_three_four') 53 self.assertEqual('one_two_three_four', m['name']) 54 55 def test_get_technologies(self): 56 c = labconfig.Configuration(['--cell', 'test', '--technology=all']) 57 t = c.get_technologies('five_six_seven_eight') 58 self.assertEqual([cellular.Technology.GPRS, cellular.Technology.EGPRS], 59 t) 60 61 c = labconfig.Configuration(['--cell=test', 62 '--technology=WCDMA,CDMA_2000']) 63 64 self.assertEqual( 65 [cellular.Technology.WCDMA, cellular.Technology.CDMA_2000], 66 c.get_technologies('five_six_seven_eight')) 67 68 def test_get_interface_ip(self): 69 self.assertEqual('127.0.0.1', labconfig.get_interface_ip('lo')) 70 71 def test_get_rf_switch_port(self): 72 c = labconfig.Configuration(['--cell', 'test', '--technology=all']) 73 self.assertEqual(0, 74 c.get_rf_switch_port('one_two_three_four')) 75 76if __name__ == '__main__': 77 unittest.main() 78