Commit 3a996a8e authored by Michael Büsch's avatar Michael Büsch

Add no-coverage annotations

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent cf8a8332
......@@ -65,12 +65,12 @@ __all__ = [
# Convenient operating system identifiers
if os.name == "java":
if os.name == "java": #@nocov
import java.lang.System
__osName = java.lang.System.getProperty("os.name").lower()
osIsWindows = __osName.startswith("windows")
osIsPosix = not osIsWindows
else:
else: #@nocov
osIsWindows = os.name == "nt" or os.name == "ce"
osIsPosix = os.name == "posix"
osIsLinux = osIsPosix and "linux" in sys.platform.lower()
......@@ -111,108 +111,108 @@ isPy3Compat = sys.version_info[0] == 3
isPy2Compat = sys.version_info[0] == 2
# Python 2/3 helper selection
def py23(py2, py3):
def py23(py2, py3): #@nocov
if isPy3Compat:
return py3
if isPy2Compat:
return py2
raise Exception("Failed to detect Python version")
raise Exception("Failed to detect Python version") #@nocov
# Python interpreter name, as string.
if isCython:
pythonInterpreter = "Cython"
pythonInterpreter = "Cython" #@nocov
elif isPyPy:
pythonInterpreter = "PyPy"
pythonInterpreter = "PyPy" #@nocov
elif isJython:
pythonInterpreter = "Jython"
pythonInterpreter = "Jython" #@nocov
elif isIronPython:
pythonInterpreter = "IronPython"
pythonInterpreter = "IronPython" #@nocov
elif isMicroPython:
pythonInterpreter = "MicroPython"
pythonInterpreter = "MicroPython" #@nocov
elif isWinStandalone:
pythonInterpreter = "CPython (frozen)"
pythonInterpreter = "CPython (frozen)" #@nocov
else:
pythonInterpreter = "CPython"
pythonInterpreter = "CPython" #@nocov
# input() compatibility.
# Force Python3 behavior
if isPy2Compat:
if isPy2Compat: #@nocov
input = raw_input
else:
else: #@nocov
input = input
# range() compatibility.
# Force Python3 behavior
if isPy2Compat:
if isPy2Compat: #@nocov
range = xrange
else:
else: #@nocov
range = range
# reduce() compatibility.
# Force Python2 behavior
if isPy3Compat:
if isPy3Compat: #@nocov
from functools import reduce
else:
else: #@nocov
reduce = reduce
# queue compatibility
# Force Python3 behavior
if isPy2Compat:
if isPy2Compat: #@nocov
import Queue as queue
else:
else: #@nocov
import queue
# BlockingIOError dummy
try:
try: #@nocov
BlockingIOError
except NameError:
except NameError: #@nocov
class BlockingIOError(BaseException): pass
BlockingIOError = BlockingIOError
# ConnectionError dummy
try:
try: #@nocov
ConnectionError
except NameError:
except NameError: #@nocov
ConnectionError = OSError
ConnectionError = ConnectionError
# Import StringIO
if isIronPython and isPy2Compat:
if isIronPython and isPy2Compat: #@nocov
# Workaround for IronPython's buggy io.StringIO
from StringIO import StringIO
else:
else: #@nocov
from io import StringIO
StringIO = StringIO
from io import BytesIO
# str.isalnum() compatibility
# This defines a global function: isalnum(string) ==> bool
if hasattr(str, "isalnum"):
if hasattr(str, "isalnum"): #@nocov
isalnum = lambda s: s.isalnum()
else:
else: #@nocov
isalnum = lambda s: all(c.isalpha() or c.isdigit() for c in s)
# str.isdecimal() compatibility
# This defines a global function: isdecimal(string) ==> bool
if hasattr(str, "isdecimal"):
if hasattr(str, "isdecimal"): #@nocov
isdecimal = lambda s: s.isdecimal()
else:
else: #@nocov
isdecimal = lambda s: all(c in "0123456789" for c in s)
# gcd() compatibility
# This defines a global function: compat_gcd(a, b) ==> int
if hasattr(math, "gcd"):
if hasattr(math, "gcd"): #@nocov
compat_gcd = math.gcd
elif hasattr(fractions, "gcd"):
elif hasattr(fractions, "gcd"): #@nocov
compat_gcd = fractions.gcd
else:
else: #@nocov
def compat_gcd(a, b):
while b:
(a, b) = (b, a % b)
return a
# contextlib.suppress compatibility
if not hasattr(contextlib, "suppress"):
if not hasattr(contextlib, "suppress"): #@nocov
class _suppress(object):
def __init__(self, *excs):
self._excs = excs
......@@ -223,7 +223,7 @@ if not hasattr(contextlib, "suppress"):
contextlib.suppress = _suppress
# contextlib.nullcontext compatibility
if not hasattr(contextlib, "nullcontext"):
if not hasattr(contextlib, "nullcontext"): #@nocov
class _nullcontext(object):
def __init__(self, enter_result=None):
self.enter_result = enter_result
......
......@@ -94,7 +94,7 @@ class S7CPUConfig(object):
if mnemonics not in (self.MNEMONICS_AUTO,
self.MNEMONICS_EN,
self.MNEMONICS_DE):
raise AwlSimError("Invalid mnemonics configuration: %d" % mnemonics)
raise AwlSimError("Invalid mnemonics configuration: %d" % mnemonics) #@nocov
self.__configuredMnemonics = mnemonics
self.setDetectedMnemonics(self.MNEMONICS_AUTO)
......
......@@ -94,7 +94,7 @@ class S7CPUSpecs(object): #+cdef
def setNrAccus(self, count):
if count not in (2, 4):
raise AwlSimError("Invalid number of accus")
raise AwlSimError("Invalid number of accus") #@nocov
self.nrAccus = count
if self.cpu:
self.cpu.reallocate()
......
......@@ -33,7 +33,7 @@ __all__ = [
]
class AwlDebug(object):
class AwlDebug(object): #@nocov
@classmethod
def getMemoryLeaks(cls):
garbageCollector.collect()
......
......@@ -39,14 +39,14 @@ def importModule(moduleName):
import awlsim_loader.cython_helper as cython_helper
try:
import importlib
except ImportError as e:
except ImportError as e: #@nocov
importlib = None
if cython_helper.shouldUseCython(moduleName):
moduleName = cython_helper.cythonModuleName(moduleName)
moduleName = cython_helper.cythonModuleName(moduleName) #@nocov
if importlib:
mod = importlib.import_module(moduleName)
else:
mod = __import__(moduleName)
mod = __import__(moduleName) #@nocov
return mod
......@@ -78,7 +78,7 @@ class MagicEnumerationGenerator(object):
self.__num = number + 1
return number
def __repr__(self):
def __repr__(self): #@nocov
return "EnumGen(num = %s)" % str(self.__num)
EnumGen = MagicEnumerationGenerator()
......@@ -244,7 +244,7 @@ class AwlParserError(AwlSimError):
def getReport(self, verbose=True):
return self.doGetReport("AWL parser error", verbose)
class AwlSimBug(AwlSimError):
class AwlSimBug(AwlSimError): #@nocov
"""AwlSim bug exception.
This will be raised in situations that represent an actual code bug.
"""
......@@ -328,7 +328,7 @@ class __suppressAllExc(object):
def __enter__(self):
pass
def __exit__(self, exctype, excinst, exctb):
def __exit__(self, exctype, excinst, exctb): #@nocov
if exctype is None:
return False # no exception
if issubclass(exctype, (SyntaxError, NameError, AttributeError)):
......
......@@ -30,11 +30,11 @@ __all__ = [
__useDummy = False
if isMicroPython:
if isMicroPython: #@nocov
__useDummy = True
if __useDummy:
if __useDummy: #@nocov
class OptionalImmutable(object):
"""Optional instance write protection.
Dummy implementation.
......@@ -74,14 +74,14 @@ else:
self._immutable = True
def __setattr__(self, name, value):
if self._immutable:
if self._immutable: #@nocov
raise AttributeError("Assignment to '%s' "
"of immutable %s." %\
(name, str(type(self))))
super(OptionalImmutable, self).__setattr__(name, value)
def __delattr__(self, name):
if self._immutable:
if self._immutable: #@nocov
raise AttributeError("Deletion of '%s' "
"from immutable %s." %\
(name, str(type(self))))
......
......@@ -104,7 +104,7 @@ class Logging(object):
cls.LOG_INFO,
cls.LOG_VERBOSE,
cls.LOG_DEBUG):
raise AwlSimError("Invalid log level '%d'" % loglevel)
raise AwlSimError("Invalid log level '%d'" % loglevel) #@nocov
cls.loglevel = loglevel
@classmethod
......@@ -124,43 +124,43 @@ class Logging(object):
stream.flush()
@classmethod
def printDebug(cls, text):
def printDebug(cls, text): #@nocov
if cls.loglevel >= cls.LOG_DEBUG:
cls.__print(sys.stdout, text)
@classmethod
def printVerbose(cls, text):
def printVerbose(cls, text): #@nocov
if cls.loglevel >= cls.LOG_VERBOSE:
cls.__print(sys.stdout, text)
@classmethod
def printInfo(cls, text):
def printInfo(cls, text): #@nocov
if cls.loglevel >= cls.LOG_INFO:
cls.__print(sys.stdout, text)
@classmethod
def printWarning(cls, text):
def printWarning(cls, text): #@nocov
if cls.loglevel >= cls.LOG_WARNING:
cls.__print(sys.stderr, text)
@classmethod
def printError(cls, text):
def printError(cls, text): #@nocov
if cls.loglevel >= cls.LOG_ERROR:
cls.__print(sys.stderr, text)
def printDebug(text):
def printDebug(text): #@nocov
Logging.printDebug(text)
def printVerbose(text):
def printVerbose(text): #@nocov
Logging.printVerbose(text)
def printInfo(text):
def printInfo(text): #@nocov
Logging.printInfo(text)
def printWarning(text):
def printWarning(text): #@nocov
Logging.printWarning(text)
def printError(text):
def printError(text): #@nocov
Logging.printError(text)
def fileExists(filename):
......@@ -181,7 +181,7 @@ def safeFileRead(filename):
with open(filename, "rb") as fd:
data = fd.read()
fd.close()
except IOError as e:
except IOError as e: #@nocov
raise AwlSimError("Failed to read '%s': %s" %\
(filename, str(e)))
return data
......@@ -199,13 +199,13 @@ def safeFileWrite(filename, data):
fd.write(data)
fd.flush()
fd.close()
if not osIsPosix:
if not osIsPosix: #@nocov
# Can't use safe rename on non-POSIX.
# Must unlink first.
with contextlib.suppress(OSError):
os.unlink(filename)
os.rename(tmpFile, filename)
except (IOError, OSError) as e:
except (IOError, OSError) as e: #@nocov
raise AwlSimError("Failed to write file:\n" + str(e))
finally:
with contextlib.suppress(IOError, OSError):
......@@ -284,19 +284,19 @@ def toDosEol(string):
"""
return toUnixEol(string).replace("\n", "\r\n")
def __isInteger_python2(value):
def __isInteger_python2(value): #@nocov
return isinstance(value, (int, long))
def __isInteger_python3(value):
def __isInteger_python3(value): #@nocov
return isinstance(value, int)
isInteger = py23(__isInteger_python2,
__isInteger_python3)
def __isString_python2(value):
def __isString_python2(value): #@nocov
return isinstance(value, (unicode, str))
def __isString_python3(value):
def __isString_python3(value): #@nocov
return isinstance(value, str)
isString = py23(__isString_python2,
......@@ -375,7 +375,7 @@ def pivotDict(inDict):
outDict = {}
for key, value in dictItems(inDict):
if value in outDict:
raise KeyError("Ambiguous key in pivot dict")
raise KeyError("Ambiguous key in pivot dict") #@nocov
outDict[value] = key
return outDict
......@@ -420,7 +420,7 @@ def clamp(value, minValue, maxValue):
ValueError is raised, if minValue is bigger than maxValue.
"""
if minValue > maxValue:
raise ValueError
raise ValueError #@nocov
return max(min(value, maxValue), minValue)
# Get "Greatest Common Divisor"
......
......@@ -55,4 +55,4 @@ class AwlInsn_FEATURE(AwlInsn): #+cdef
self.cpu.enableObTempPresets(value)
self.cpu.accu1.set(int(self.cpu.obTempPresetsEnabled()))
else:
raise AwlSimError("Unsupported __FEATURE target %d" % target)
raise AwlSimError("Unsupported __FEATURE target %d" % target) #@nocov
......@@ -45,7 +45,7 @@ class AwlInsn_SLEEP(AwlInsn): #+cdef
sleepSecs = sleepMsecs / 1000.0
if sleepSecs >= self.cpu.cycleTimeLimit:
raise AwlSimError("__SLEEP time exceed cycle time limit")
raise AwlSimError("__SLEEP time exceed cycle time limit") #@nocov
self.cpu.updateTimestamp()
start = self.cpu.now
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment