test_testrun.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import pytest
  2. from unittest.mock import patch
  3. from baangt.base.TestRun.TestRun import TestRun
  4. class subprocess_communicate:
  5. def __init__(self, *stdout, **stderr):
  6. pass
  7. def communicate(self):
  8. return b"firefox\n", 1
  9. @pytest.fixture
  10. def testrun_obj():
  11. """ This function return instance of TestRun object
  12. which will be used by other test methods
  13. """
  14. return TestRun("examples/SimpleTheInternet.xlsx","globals.json", executeDirect=False)
  15. def test_filenotfound():
  16. """ To check if function raises File not found Error """
  17. with pytest.raises(BaseException) as e:
  18. TestRun("SimpleTheInternet.xlsx","global.json")
  19. def test_objectreturned(testrun_obj):
  20. """ Returns number of successful and number of error test cases of
  21. the current test run
  22. """
  23. from baangt.base.TestRun.TestRun import TestRun
  24. assert TestRun.__instancecheck__(testrun_obj)
  25. def test_checkattribute(testrun_obj):
  26. """ check if has attribute """
  27. assert hasattr(testrun_obj, "getSuccessAndError")
  28. assert hasattr(testrun_obj, "setResult")
  29. @pytest.mark.xfail(testrun_obj, reason="TestRun didn't return object")
  30. def test_getSuccessAndError(testrun_obj):
  31. """ This function test getSuccessAndError method
  32. working or not
  33. """
  34. assert (0,1) == testrun_obj.getSuccessAndError()
  35. @pytest.mark.xfail(testrun_obj, reason="TestRun didn't return object")
  36. def test_setResult(testrun_obj):
  37. """ check setResult Function """
  38. # get the previous result
  39. old_result = testrun_obj.getSuccessAndError()
  40. testrun_obj.setResult(1,0)
  41. # check the result
  42. new_result = set(old_result[0]+1, old_result[1])
  43. assert new_result == testrun_obj.getSuccessAndError()
  44. @pytest.mark.parametrize("system, os_version", [
  45. ("Linux", ["redhat-release"]),
  46. ("Linux", ["debian_version"]),
  47. ("Darwin", ["firefox"]),
  48. ("Darwin", ["chrome"])
  49. ])
  50. @patch("subprocess.Popen", subprocess_communicate)
  51. @patch("os.listdir")
  52. @patch("platform.system")
  53. def test_ExcelImporter(mock_plat, mock_list, system, os_version):
  54. from baangt.base.TestRunExcelImporter import TestRunExcelImporter
  55. mock_plat.return_value = system
  56. mock_list.return_value = os_version
  57. TestRunExcelImporter.get_browser(TestRunExcelImporter)
  58. assert mock_plat.call_count > 0