From 9777ab3619c7036fad3dbd49efdf10d9d9e2a18e Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Wed, 4 Dec 2019 00:59:21 +0000 Subject: [PATCH] depot_tools: Add tests for detect_host_arch. Change-Id: Ife5826fc824f1304bc1a8ae09c0a659583f0ffb1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1949408 Auto-Submit: Edward Lesmes Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- detect_host_arch.py | 1 - tests/detect_host_arch_test.py | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/detect_host_arch_test.py diff --git a/detect_host_arch.py b/detect_host_arch.py index 69c50f870..5aec2c87d 100755 --- a/detect_host_arch.py +++ b/detect_host_arch.py @@ -9,7 +9,6 @@ from __future__ import print_function import platform import re -import sys def HostArch(): diff --git a/tests/detect_host_arch_test.py b/tests/detect_host_arch_test.py new file mode 100644 index 000000000..ea6760f15 --- /dev/null +++ b/tests/detect_host_arch_test.py @@ -0,0 +1,51 @@ +#!/usr/bin/env vpython3 +# Copyright 2019 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import platform +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import detect_host_arch +from third_party import mock + + +class DetectHostArchTest(unittest.TestCase): + def setUp(self): + super(DetectHostArchTest, self).setUp() + mock.patch('platform.machine').start() + mock.patch('platform.processor').start() + mock.patch('platform.architecture').start() + self.addCleanup(mock.patch.stopall) + + def testHostArch(self): + test_cases = [ + ('ia86', '', [''], 'x86'), + ('i86pc', '', [''], 'x86'), + ('x86_64', '', [''], 'x64'), + ('amd64', '', [''], 'x64'), + ('x86_64', '', ['32bit'], 'x86'), + ('amd64', '', ['32bit'], 'x86'), + ('arm', '', [''], 'arm'), + ('aarch64', '', [''], 'arm64'), + ('aarch64', '', ['32bit'], 'arm'), + ('mips64', '', [''], 'mips64'), + ('mips', '', [''], 'mips'), + ('ppc', '', [''], 'ppc'), + ('foo', 'powerpc', [''], 'ppc'), + ('s390', '', [''], 's390'), + ] + + for machine, processor, arch, expected in test_cases: + platform.machine.return_value = machine + platform.processor.return_value = processor + platform.architecture.return_value = arch + self.assertEqual(expected, detect_host_arch.HostArch()) + + +if __name__ == '__main__': + unittest.main()