test_refactor.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Test script to verify the refactoring is successful
  5. import sys
  6. import os
  7. # Add current directory to path
  8. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  9. # Mock rtconfig module for testing
  10. import mock_rtconfig
  11. sys.modules['rtconfig'] = mock_rtconfig
  12. def test_targets_import():
  13. """Test if all target modules can be imported successfully"""
  14. print("Testing targets module imports...")
  15. try:
  16. # Test importing targets module
  17. import targets
  18. print("✓ targets module imported successfully")
  19. # Test importing individual target modules
  20. target_modules = [
  21. 'keil', 'iar', 'vs', 'vs2012', 'codeblocks', 'ua',
  22. 'vsc', 'cdk', 'ses', 'eclipse', 'codelite',
  23. 'cmake', 'xmake', 'esp_idf', 'zigbuild', 'makefile', 'rt_studio'
  24. ]
  25. for module_name in target_modules:
  26. try:
  27. module = getattr(targets, module_name)
  28. print(f"✓ {module_name} module imported successfully")
  29. except AttributeError as e:
  30. print(f"✗ Failed to import {module_name}: {e}")
  31. return False
  32. return True
  33. except ImportError as e:
  34. print(f"✗ Failed to import targets module: {e}")
  35. return False
  36. def test_building_import():
  37. """Test if building.py can import target modules"""
  38. print("\nTesting building.py imports...")
  39. try:
  40. # Test importing building module
  41. import building
  42. print("✓ building module imported successfully")
  43. # Test if GenTargetProject function exists
  44. if hasattr(building, 'GenTargetProject'):
  45. print("✓ GenTargetProject function found")
  46. else:
  47. print("✗ GenTargetProject function not found")
  48. return False
  49. return True
  50. except ImportError as e:
  51. print(f"✗ Failed to import building module: {e}")
  52. return False
  53. def test_target_functions():
  54. """Test if target functions can be called"""
  55. print("\nTesting target function calls...")
  56. try:
  57. # Test importing specific target functions
  58. from targets.keil import MDK4Project, MDK5Project
  59. print("✓ Keil target functions imported successfully")
  60. from targets.iar import IARProject
  61. print("✓ IAR target functions imported successfully")
  62. from targets.eclipse import TargetEclipse
  63. print("✓ Eclipse target functions imported successfully")
  64. from targets.cmake import CMakeProject
  65. print("✓ CMake target functions imported successfully")
  66. import targets.rt_studio
  67. print("✓ RT-Studio target functions imported successfully")
  68. return True
  69. except ImportError as e:
  70. print(f"✗ Failed to import target functions: {e}")
  71. return False
  72. def main():
  73. """Main test function"""
  74. print("RT-Thread Tools Refactoring Test")
  75. print("=" * 40)
  76. success = True
  77. # Run all tests
  78. if not test_targets_import():
  79. success = False
  80. if not test_building_import():
  81. success = False
  82. if not test_target_functions():
  83. success = False
  84. print("\n" + "=" * 40)
  85. if success:
  86. print("✓ All tests passed! Refactoring is successful.")
  87. return 0
  88. else:
  89. print("✗ Some tests failed. Please check the errors above.")
  90. return 1
  91. if __name__ == '__main__':
  92. sys.exit(main())