1#!/usr/bin/env python3 2# 3# Copyright 2018 - 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 17"""Unittests for android_dev_os.""" 18 19import unittest 20from unittest import mock 21 22from aidegen.lib.android_dev_os import AndroidDevOS 23 24 25class IdeUtilUnittests(unittest.TestCase): 26 """Unit tests for android_dev_os.""" 27 28 @mock.patch('platform.system', return_value='Darwin') 29 def test_get_os_info_mac(self, mock_system): 30 """Test with running in Mac""" 31 mock_system.return_value = 'Darwin' 32 self.assertTrue(AndroidDevOS.MAC == AndroidDevOS.get_os_type()) 33 self.assertFalse(AndroidDevOS.LINUX == AndroidDevOS.get_os_type()) 34 self.assertFalse(AndroidDevOS.WINDOWS == AndroidDevOS.get_os_type()) 35 self.assertTrue(AndroidDevOS.get_os_name() == 'MAC') 36 37 @mock.patch('platform.system', return_value='Linux') 38 def test_get_os_info_linux(self, mock_system): 39 """Test with running in Linux""" 40 mock_system.return_value = 'Linux' 41 self.assertFalse(AndroidDevOS.MAC == AndroidDevOS.get_os_type()) 42 self.assertTrue(AndroidDevOS.LINUX == AndroidDevOS.get_os_type()) 43 self.assertFalse(AndroidDevOS.WINDOWS == AndroidDevOS.get_os_type()) 44 self.assertTrue(AndroidDevOS.get_os_name() == 'LINUX') 45 46 @mock.patch('platform.system', return_value='Windows') 47 def test_get_os_info_windows(self, mock_system): 48 """Test with running in Windows""" 49 mock_system.return_value = 'Windows' 50 self.assertFalse(AndroidDevOS.MAC == AndroidDevOS.get_os_type()) 51 self.assertFalse(AndroidDevOS.LINUX == AndroidDevOS.get_os_type()) 52 self.assertTrue(AndroidDevOS.WINDOWS == AndroidDevOS.get_os_type()) 53 self.assertTrue(AndroidDevOS.get_os_name() == 'WINDOWS') 54 55 @mock.patch('platform.system', return_value='None') 56 def test_get_os_info_default(self, mock_system): 57 """Test with running in unknown""" 58 mock_system.return_value = 'None' 59 self.assertFalse(AndroidDevOS.MAC == AndroidDevOS.get_os_type()) 60 self.assertTrue(AndroidDevOS.LINUX == AndroidDevOS.get_os_type()) 61 self.assertFalse(AndroidDevOS.WINDOWS == AndroidDevOS.get_os_type()) 62 self.assertTrue(AndroidDevOS.get_os_name() == 'LINUX') 63 64 65if __name__ == '__main__': 66 unittest.main() 67