test_device_capabilities.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import unittest
  2. from unittest.mock import patch
  3. from topology.device_capabilities import mac_device_capabilities, DeviceCapabilities
  4. class TestMacDeviceCapabilities(unittest.TestCase):
  5. @patch('subprocess.check_output')
  6. def test_mac_device_capabilities(self, mock_check_output):
  7. # Mock the subprocess output
  8. mock_check_output.return_value = b"""
  9. Hardware:
  10. Hardware Overview:
  11. Model Name: MacBook Pro
  12. Model Identifier: Mac15,9
  13. Model Number: Z1CM000EFB/A
  14. Chip: Apple M3 Max
  15. Total Number of Cores: 16 (12 performance and 4 efficiency)
  16. Memory: 128 GB
  17. System Firmware Version: 10000.000.0
  18. OS Loader Version: 10000.000.0
  19. Serial Number (system): XXXXXXXXXX
  20. Hardware UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  21. Provisioning UDID: XXXXXXXX-XXXXXXXXXXXXXXXX
  22. Activation Lock Status: Enabled
  23. """
  24. # Call the function
  25. result = mac_device_capabilities()
  26. # Check the results
  27. self.assertIsInstance(result, DeviceCapabilities)
  28. self.assertEqual(result.model, "MacBook Pro")
  29. self.assertEqual(result.chip, "Apple M3 Max")
  30. self.assertEqual(result.memory, 131072) # 16 GB in MB
  31. @patch('subprocess.check_output')
  32. def test_mac_device_capabilities(self, mock_check_output):
  33. # Mock the subprocess output
  34. mock_check_output.return_value = b"""
  35. Hardware:
  36. Hardware Overview:
  37. Model Name: MacBook Air
  38. Model Identifier: Mac14,2
  39. Model Number: MLY33B/A
  40. Chip: Apple M2
  41. Total Number of Cores: 8 (4 performance and 4 efficiency)
  42. Memory: 8 GB
  43. System Firmware Version: 10000.00.0
  44. OS Loader Version: 10000.00.0
  45. Serial Number (system): XXXXXXXXXX
  46. Hardware UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  47. Provisioning UDID: XXXXXXXX-XXXXXXXXXXXXXXXX
  48. Activation Lock Status: Disabled
  49. """
  50. # Call the function
  51. result = mac_device_capabilities()
  52. # Check the results
  53. self.assertIsInstance(result, DeviceCapabilities)
  54. self.assertEqual(result.model, "MacBook Air")
  55. self.assertEqual(result.chip, "Apple M2")
  56. self.assertEqual(result.memory, 8192) # 8 GB in MB
  57. @unittest.skip("Unskip this test when running on a MacBook Pro, Apple M3 Max, 128GB")
  58. def test_mac_device_capabilities_real(self):
  59. # Call the function without mocking
  60. result = mac_device_capabilities()
  61. # Check the results
  62. self.assertIsInstance(result, DeviceCapabilities)
  63. self.assertEqual(result.model, "MacBook Pro")
  64. self.assertEqual(result.chip, "Apple M3 Max")
  65. self.assertEqual(result.memory, 131072) # 128 GB in MB
  66. if __name__ == '__main__':
  67. unittest.main()