src/eric7/RemoteServerInterface/EricServerCoverageInterface.py

branch
server
changeset 10577
b9edebd77c91
parent 10575
abde60847db6
child 11090
f5f5f5803935
diff -r 0cf5ebf17411 -r b9edebd77c91 src/eric7/RemoteServerInterface/EricServerCoverageInterface.py
--- a/src/eric7/RemoteServerInterface/EricServerCoverageInterface.py	Fri Feb 16 11:45:08 2024 +0100
+++ b/src/eric7/RemoteServerInterface/EricServerCoverageInterface.py	Fri Feb 16 16:48:32 2024 +0100
@@ -72,18 +72,22 @@
                     error = params["error"]
                 loop.quit()
 
-        self.__serverInterface.sendJson(
-            category=EricRequestCategory.Coverage,
-            request="LoadData",
-            params={
-                "data_file": FileSystemUtilities.plainFileName(dataFile),
-                "exclude": excludePattern,
-            },
-            callback=callback,
-        )
+        if self.__serverInterface.isServerConnected():
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.Coverage,
+                request="LoadData",
+                params={
+                    "data_file": FileSystemUtilities.plainFileName(dataFile),
+                    "exclude": excludePattern,
+                },
+                callback=callback,
+            )
 
-        loop.exec()
-        return ok, error
+            loop.exec()
+            return ok, error
+
+        else:
+            return False, "Not connected to an 'eric-ide' server."
 
     def analyzeFile(self, filename):
         """
@@ -93,7 +97,8 @@
         @type str
         @return list containing coverage result as reported by Coverage.analysis2()
         @rtype list of [str, list of int, list of int, list of int, str]
-        @exception EricServerCoverageException raised to indicate a coverage exception
+        @exception EricServerCoverageError raised to indicate a coverage exception
+        @exception OSError raised to indicate that server is not connected
         """
         loop = QEventLoop()
         ok = False
@@ -119,18 +124,22 @@
                     error = params["error"]
                 loop.quit()
 
-        self.__serverInterface.sendJson(
-            category=EricRequestCategory.Coverage,
-            request="AnalyzeFile",
-            params={"filename": FileSystemUtilities.plainFileName(filename)},
-            callback=callback,
-        )
+        if not self.__serverInterface.isServerConnected():
+            raise OSError("Not connected to an 'eric-ide' server.")
 
-        loop.exec()
-        if not ok:
-            raise EricServerCoverageError(error)
+        else:
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.Coverage,
+                request="AnalyzeFile",
+                params={"filename": FileSystemUtilities.plainFileName(filename)},
+                callback=callback,
+            )
 
-        return result
+            loop.exec()
+            if not ok:
+                raise EricServerCoverageError(error)
+
+            return result
 
     def analyzeFiles(self, filenames):
         """
@@ -140,7 +149,8 @@
         @type str
         @return lists containing coverage results as reported by Coverage.analysis2()
         @rtype list of [list of [str, list of int, list of int, list of int, str]]
-        @exception EricServerCoverageException raised to indicate a coverage exception
+        @exception EricServerCoverageError raised to indicate a coverage exception
+        @exception OSError raised to indicate that server is not connected
         """
         loop = QEventLoop()
         ok = False
@@ -166,20 +176,26 @@
                     error = params["error"]
                 loop.quit()
 
-        self.__serverInterface.sendJson(
-            category=EricRequestCategory.Coverage,
-            request="AnalyzeFiles",
-            params={
-                "filenames": [FileSystemUtilities.plainFileName(f) for f in filenames]
-            },
-            callback=callback,
-        )
+        if not self.__serverInterface.isServerConnected():
+            raise OSError("Not connected to an 'eric-ide' server.")
 
-        loop.exec()
-        if not ok:
-            raise EricServerCoverageError(error)
+        else:
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.Coverage,
+                request="AnalyzeFiles",
+                params={
+                    "filenames": [
+                        FileSystemUtilities.plainFileName(f) for f in filenames
+                    ]
+                },
+                callback=callback,
+            )
 
-        return result
+            loop.exec()
+            if not ok:
+                raise EricServerCoverageError(error)
+
+            return result
 
     def analyzeDirectory(self, directory):
         """
@@ -189,7 +205,8 @@
         @type str
         @return lists containing coverage results as reported by Coverage.analysis2()
         @rtype list of [list of [str, list of int, list of int, list of int, str]]
-        @exception EricServerCoverageException raised to indicate a coverage exception
+        @exception EricServerCoverageError raised to indicate a coverage exception
+        @exception OSError raised to indicate that server is not connected
         """
         loop = QEventLoop()
         ok = False
@@ -215,15 +232,19 @@
                     error = params["error"]
                 loop.quit()
 
-        self.__serverInterface.sendJson(
-            category=EricRequestCategory.Coverage,
-            request="AnalyzeDirectory",
-            params={"directory": FileSystemUtilities.plainFileName(directory)},
-            callback=callback,
-        )
+        if not self.__serverInterface.isServerConnected():
+            raise OSError("Not connected to an 'eric-ide' server.")
 
-        loop.exec()
-        if not ok:
-            raise EricServerCoverageError(error)
+        else:
+            self.__serverInterface.sendJson(
+                category=EricRequestCategory.Coverage,
+                request="AnalyzeDirectory",
+                params={"directory": FileSystemUtilities.plainFileName(directory)},
+                callback=callback,
+            )
 
-        return result
+            loop.exec()
+            if not ok:
+                raise EricServerCoverageError(error)
+
+            return result

eric ide

mercurial