798 self.sessionClose() |
799 self.sessionClose() |
799 |
800 |
800 elif method == "RequestCompletion": |
801 elif method == "RequestCompletion": |
801 self.__completionList(params["text"]) |
802 self.__completionList(params["text"]) |
802 |
803 |
803 elif method == "RequestUTPrepare": |
804 elif method == "RequestUTDiscover": |
804 sys.path.insert( |
805 if params["syspath"]: |
805 0, os.path.dirname(os.path.abspath(params["filename"]))) |
806 sys.path = params["syspath"] + sys.path |
806 os.chdir(sys.path[0]) |
807 |
|
808 discoveryStart = params["discoverystart"] |
|
809 if not discoveryStart: |
|
810 discoveryStart = params["workdir"] |
|
811 |
|
812 os.chdir(params["discoverystart"]) |
807 |
813 |
808 # set the system exception handling function to ensure, that |
814 # set the system exception handling function to ensure, that |
809 # we report on all unhandled exceptions |
815 # we report on all unhandled exceptions |
810 sys.excepthook = self.__unhandled_exception |
816 sys.excepthook = self.__unhandled_exception |
811 self.__interceptSignals() |
817 self.__interceptSignals() |
812 |
818 |
813 try: |
819 try: |
814 import unittest |
820 import unittest |
815 utModule = imp.load_source( |
821 testLoader = unittest.TestLoader() |
816 params["testname"], params["filename"]) |
822 test = testLoader.discover(discoveryStart) |
817 try: |
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 discoveryStart) |
|
833 self.sendJsonCommand("ResponseUTDiscover", { |
|
834 "testCasesList": testsList, |
|
835 "exception": "", |
|
836 "message": "", |
|
837 }) |
|
838 except Exception: |
|
839 exc_type, exc_value, exc_tb = sys.exc_info() |
|
840 self.sendJsonCommand("ResponseUTDiscover", { |
|
841 "testCasesList": [], |
|
842 "exception": exc_type.__name__, |
|
843 "message": str(exc_value), |
|
844 }) |
|
845 |
|
846 elif method == "RequestUTPrepare": |
|
847 if params["syspath"]: |
|
848 sys.path = params["syspath"] + sys.path |
|
849 sys.path.insert( |
|
850 0, os.path.dirname(os.path.abspath(params["filename"]))) |
|
851 if params["workdir"]: |
|
852 os.chdir(params["workdir"]) |
|
853 else: |
|
854 os.chdir(sys.path[0]) |
|
855 |
|
856 # set the system exception handling function to ensure, that |
|
857 # we report on all unhandled exceptions |
|
858 sys.excepthook = self.__unhandled_exception |
|
859 self.__interceptSignals() |
|
860 |
|
861 try: |
|
862 import unittest |
|
863 testLoader = unittest.TestLoader() |
|
864 if params["discover"]: |
|
865 discoveryStart = params["discoverystart"] |
|
866 if not discoveryStart: |
|
867 discoveryStart = params["workdir"] |
|
868 if params["testcases"]: |
|
869 self.test = testLoader.loadTestsFromNames( |
|
870 params["testcases"]) |
|
871 else: |
|
872 self.test = testLoader.discover(discoveryStart) |
|
873 else: |
|
874 if params["filename"]: |
|
875 utModule = imp.load_source( |
|
876 params["testname"], params["filename"]) |
|
877 else: |
|
878 utModule = None |
818 if params["failed"]: |
879 if params["failed"]: |
819 self.test = unittest.defaultTestLoader\ |
880 if utModule: |
820 .loadTestsFromNames(params["failed"], utModule) |
881 failed = [t.split(".", 1)[1] |
|
882 for t in params["failed"]] |
|
883 else: |
|
884 failed = params["failed"][:] |
|
885 self.test = testLoader.loadTestsFromNames( |
|
886 failed, utModule) |
821 else: |
887 else: |
822 self.test = unittest.defaultTestLoader\ |
888 self.test = testLoader.loadTestsFromName( |
823 .loadTestsFromName(params["testfunctionname"], |
889 params["testfunctionname"], utModule) |
824 utModule) |
|
825 except AttributeError: |
|
826 self.test = unittest.defaultTestLoader\ |
|
827 .loadTestsFromModule(utModule) |
|
828 except Exception: |
890 except Exception: |
829 exc_type, exc_value, exc_tb = sys.exc_info() |
891 exc_type, exc_value, exc_tb = sys.exc_info() |
830 self.sendJsonCommand("ResponseUTPrepared", { |
892 self.sendJsonCommand("ResponseUTPrepared", { |
831 "count": 0, |
893 "count": 0, |
832 "exception": exc_type.__name__, |
894 "exception": exc_type.__name__, |
844 if params["coverageerase"]: |
906 if params["coverageerase"]: |
845 self.cover.erase() |
907 self.cover.erase() |
846 else: |
908 else: |
847 self.cover = None |
909 self.cover = None |
848 |
910 |
|
911 if params["debug"]: |
|
912 Breakpoint.clear_all_breaks() |
|
913 Watch.clear_all_watches() |
|
914 |
849 self.sendJsonCommand("ResponseUTPrepared", { |
915 self.sendJsonCommand("ResponseUTPrepared", { |
850 "count": self.test.countTestCases(), |
916 "count": self.test.countTestCases(), |
851 "exception": "", |
917 "exception": "", |
852 "message": "", |
918 "message": "", |
853 }) |
919 }) |
854 |
920 |
855 elif method == "RequestUTRun": |
921 elif method == "RequestUTRun": |
856 from DCTestResult import DCTestResult |
922 from DCTestResult import DCTestResult |
857 self.testResult = DCTestResult(self) |
923 self.testResult = DCTestResult(self, params["failfast"]) |
858 if self.cover: |
924 if self.cover: |
859 self.cover.start() |
925 self.cover.start() |
860 self.test.run(self.testResult) |
926 self.debugging = params["debug"] |
|
927 if params["debug"]: |
|
928 locals_ = locals() |
|
929 self.threads.clear() |
|
930 self.attachThread(mainThread=True) |
|
931 sys.setprofile(None) |
|
932 self.mainThread.run( |
|
933 "result = self.test.run(self.testResult)\n", |
|
934 localsDict=locals_) |
|
935 result = locals_["result"] |
|
936 else: |
|
937 result = self.test.run(self.testResult) |
861 if self.cover: |
938 if self.cover: |
862 self.cover.stop() |
939 self.cover.stop() |
863 self.cover.save() |
940 self.cover.save() |
864 self.sendJsonCommand("ResponseUTFinished", {}) |
941 self.sendJsonCommand("ResponseUTFinished", { |
|
942 "status": 0 if result.wasSuccessful() else 1, |
|
943 }) |
865 |
944 |
866 elif method == "RequestUTStop": |
945 elif method == "RequestUTStop": |
867 self.testResult.stop() |
946 self.testResult.stop() |
868 |
947 |
869 elif method == "ResponseForkTo": |
948 elif method == "ResponseForkTo": |
870 # this results from a separate event loop |
949 # this results from a separate event loop |
871 self.fork_child = (params["target"] == 'child') |
950 self.fork_child = (params["target"] == 'child') |
872 self.eventExit = True |
951 self.eventExit = True |
|
952 |
|
953 def __assembleTestCasesList(self, suite, start): |
|
954 """ |
|
955 Private method to assemble a list of test cases included in a test |
|
956 suite. |
|
957 |
|
958 @param suite test suite to be inspected |
|
959 @type unittest.TestSuite |
|
960 @param start name of directory discovery was started at |
|
961 @type str |
|
962 @return list of tuples containing the test case ID, a short description |
|
963 and the path of the test file name |
|
964 @rtype list of tuples of (str, str, str) |
|
965 """ |
|
966 import unittest |
|
967 testCases = [] |
|
968 for test in suite: |
|
969 if isinstance(test, unittest.TestSuite): |
|
970 testCases.extend(self.__assembleTestCasesList(test, start)) |
|
971 else: |
|
972 testId = test.id() |
|
973 if "ModuleImportFailure" not in testId and \ |
|
974 "LoadTestsFailure" not in testId and \ |
|
975 "_FailedTest" not in testId: |
|
976 filename = os.path.join( |
|
977 start, |
|
978 test.__module__.replace(".", os.sep) + ".py") |
|
979 testCases.append( |
|
980 (test.id(), test.shortDescription(), filename) |
|
981 ) |
|
982 return testCases |
873 |
983 |
874 def sendJsonCommand(self, method, params): |
984 def sendJsonCommand(self, method, params): |
875 """ |
985 """ |
876 Public method to send a single command or response to the IDE. |
986 Public method to send a single command or response to the IDE. |
877 |
987 |
2071 try: |
2190 try: |
2072 redirect = int(sys.argv[2]) |
2191 redirect = int(sys.argv[2]) |
2073 except (ValueError, IndexError): |
2192 except (ValueError, IndexError): |
2074 redirect = True |
2193 redirect = True |
2075 |
2194 |
2076 try: |
2195 ipOrHost = sys.argv[3] |
2077 ipOrHost = sys.argv[3] |
2196 if ':' in ipOrHost: |
2078 if ':' in ipOrHost: |
2197 # IPv6 address |
2079 remoteAddress = ipOrHost |
2198 remoteAddress = ipOrHost |
2080 elif ipOrHost[0] in '0123456789': |
2199 elif ipOrHost[0] in '0123456789': |
2081 remoteAddress = ipOrHost |
2200 # IPv4 address |
2082 else: |
2201 remoteAddress = ipOrHost |
2083 remoteAddress = self.__resolveHost(ipOrHost) |
2202 else: |
2084 except Exception: |
2203 remoteAddress = self.__resolveHost(ipOrHost) |
2085 remoteAddress = None |
|
2086 |
2204 |
2087 sys.argv = [''] |
2205 sys.argv = [''] |
2088 if '' not in sys.path: |
2206 if '' not in sys.path: |
2089 sys.path.insert(0, '') |
2207 sys.path.insert(0, '') |
2090 |
2208 |