| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
from cpuinfo import * |
| 5 |
import helpers |
| 6 |
|
| 7 |
|
| 8 |
class MockDataSource: |
| 9 |
bits = '32bit' |
| 10 |
cpu_count = 1 |
| 11 |
is_windows = False |
| 12 |
arch_string_raw = 'unknown_cpu' |
| 13 |
uname_string_raw = 'unknown_cpu' |
| 14 |
|
| 15 |
|
| 16 |
class TestInvalidCPU(unittest.TestCase): |
| 17 |
def setUp(self): |
| 18 |
helpers.backup_data_source(cpuinfo) |
| 19 |
helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
| 20 |
|
| 21 |
def tearDown(self): |
| 22 |
helpers.restore_data_source(cpuinfo) |
| 23 |
|
| 24 |
def test_arch_parse_unknown(self): |
| 25 |
# If the arch is unknown, the result should be null |
| 26 |
arch, bits = cpuinfo._parse_arch(DataSource.arch_string_raw) |
| 27 |
self.assertIsNone(arch) |
| 28 |
self.assertIsNone(bits) |
| 29 |
|
| 30 |
def test_check_arch_exception(self): |
| 31 |
# If the arch is unknown, it should raise and exception |
| 32 |
try: |
| 33 |
cpuinfo._check_arch() |
| 34 |
self.fail('Failed to raise Exception') |
| 35 |
except Exception as err: |
| 36 |
self.assertEqual('py-cpuinfo currently only works on X86 and some ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs.', err.args[0]) |