799 self.sessionClose() |
799 self.sessionClose() |
800 |
800 |
801 elif method == "RequestCompletion": |
801 elif method == "RequestCompletion": |
802 self.__completionList(params["text"]) |
802 self.__completionList(params["text"]) |
803 |
803 |
|
804 elif method == "RequestUTDiscover": |
|
805 if params["syspath"]: |
|
806 sys.path = params["syspath"] + sys.path |
|
807 |
|
808 discoveryStart = params["discoverystart"] |
|
809 if not discoveryStart: |
|
810 discoveryStart = params["workdir"] |
|
811 |
|
812 os.chdir(params["discoverystart"]) |
|
813 |
|
814 # set the system exception handling function to ensure, that |
|
815 # we report on all unhandled exceptions |
|
816 sys.excepthook = self.__unhandled_exception |
|
817 self.__interceptSignals() |
|
818 |
|
819 try: |
|
820 import unittest |
|
821 testLoader = unittest.TestLoader() |
|
822 test = testLoader.discover(discoveryStart) |
|
823 if hasattr(testLoader, "errors") and \ |
|
824 bool(testLoader.errors): |
|
825 self.sendJsonCommand("ResponseUTDiscover", { |
|
826 "testCasesList": [], |
|
827 "exception": "DiscoveryError", |
|
828 "message": "\n\n".join(testLoader.errors), |
|
829 }) |
|
830 else: |
|
831 testsList = self.__assembleTestCasesList(test) |
|
832 self.sendJsonCommand("ResponseUTDiscover", { |
|
833 "testCasesList": testsList, |
|
834 "exception": "", |
|
835 "message": "", |
|
836 }) |
|
837 except Exception: |
|
838 exc_type, exc_value, exc_tb = sys.exc_info() |
|
839 self.sendJsonCommand("ResponseUTDiscover", { |
|
840 "testCasesList": [], |
|
841 "exception": exc_type.__name__, |
|
842 "message": str(exc_value), |
|
843 }) |
|
844 |
804 elif method == "RequestUTPrepare": |
845 elif method == "RequestUTPrepare": |
805 if params["syspath"]: |
846 if params["syspath"]: |
806 sys.path = params["syspath"] + sys.path |
847 sys.path = params["syspath"] + sys.path |
807 sys.path.insert( |
848 sys.path.insert( |
808 0, os.path.dirname(os.path.abspath(params["filename"]))) |
849 0, os.path.dirname(os.path.abspath(params["filename"]))) |
816 sys.excepthook = self.__unhandled_exception |
857 sys.excepthook = self.__unhandled_exception |
817 self.__interceptSignals() |
858 self.__interceptSignals() |
818 |
859 |
819 try: |
860 try: |
820 import unittest |
861 import unittest |
|
862 testLoader = unittest.TestLoader() |
821 if params["discover"]: |
863 if params["discover"]: |
822 discoveryStart = params["discoverystart"] |
864 discoveryStart = params["discoverystart"] |
823 if not discoveryStart: |
865 if not discoveryStart: |
824 discoveryStart = params["workdir"] |
866 discoveryStart = params["workdir"] |
825 self.test = unittest.defaultTestLoader.discover( |
867 if params["testcases"]: |
826 discoveryStart) |
868 self.test = testLoader.loadTestsFromNames( |
|
869 params["testcases"]) |
|
870 else: |
|
871 self.test = testLoader.discover(discoveryStart) |
827 else: |
872 else: |
828 if params["filename"]: |
873 if params["filename"]: |
829 utModule = imp.load_source( |
874 utModule = imp.load_source( |
830 params["testname"], params["filename"]) |
875 params["testname"], params["filename"]) |
831 else: |
876 else: |
834 if utModule: |
879 if utModule: |
835 failed = [t.split(".", 1)[1] |
880 failed = [t.split(".", 1)[1] |
836 for t in params["failed"]] |
881 for t in params["failed"]] |
837 else: |
882 else: |
838 failed = params["failed"][:] |
883 failed = params["failed"][:] |
839 self.test = unittest.defaultTestLoader\ |
884 self.test = testLoader.loadTestsFromNames( |
840 .loadTestsFromNames(failed, utModule) |
885 failed, utModule) |
841 else: |
886 else: |
842 self.test = unittest.defaultTestLoader\ |
887 self.test = testLoader.loadTestsFromName( |
843 .loadTestsFromName(params["testfunctionname"], |
888 params["testfunctionname"], utModule) |
844 utModule) |
|
845 except Exception: |
889 except Exception: |
846 exc_type, exc_value, exc_tb = sys.exc_info() |
890 exc_type, exc_value, exc_tb = sys.exc_info() |
847 self.sendJsonCommand("ResponseUTPrepared", { |
891 self.sendJsonCommand("ResponseUTPrepared", { |
848 "count": 0, |
892 "count": 0, |
849 "exception": exc_type.__name__, |
893 "exception": exc_type.__name__, |
850 "message": str(exc_value) + "<br/>" + str(params), |
894 "message": str(exc_value), |
851 }) |
895 }) |
852 return |
896 return |
853 |
897 |
854 # generate a coverage object |
898 # generate a coverage object |
855 if params["coverage"]: |
899 if params["coverage"]: |
885 |
929 |
886 elif method == "ResponseForkTo": |
930 elif method == "ResponseForkTo": |
887 # this results from a separate event loop |
931 # this results from a separate event loop |
888 self.fork_child = (params["target"] == 'child') |
932 self.fork_child = (params["target"] == 'child') |
889 self.eventExit = True |
933 self.eventExit = True |
|
934 |
|
935 def __assembleTestCasesList(self, suite): |
|
936 """ |
|
937 Private method to assemble a list of test cases included in a test |
|
938 suite. |
|
939 |
|
940 @param suite test suite to be inspected |
|
941 @type unittest.TestSuite |
|
942 @return list of tuples containing the test case ID and short |
|
943 description |
|
944 @rtype list of tuples of (str, str) |
|
945 """ |
|
946 import unittest |
|
947 testCases = [] |
|
948 for test in suite: |
|
949 if isinstance(test, unittest.TestSuite): |
|
950 testCases.extend(self.__assembleTestCasesList(test)) |
|
951 else: |
|
952 testId = test.id() |
|
953 if "ModuleImportFailure" not in testId and \ |
|
954 "LoadTestsFailure" not in testId and \ |
|
955 "_FailedTest" not in testId: |
|
956 testCases.append((test.id(), test.shortDescription())) |
|
957 return testCases |
890 |
958 |
891 def sendJsonCommand(self, method, params): |
959 def sendJsonCommand(self, method, params): |
892 """ |
960 """ |
893 Public method to send a single command or response to the IDE. |
961 Public method to send a single command or response to the IDE. |
894 |
962 |