1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

pytest/coverage: Resolve the "which way around to have pragmas" issue

1. You end up either inverting the sense of a `coverage_conditional_plugin`
  pragma's name (versus what it actually tests), *or* where you put it in
  the code.
2. As the pragmas are only defined in once, in one place, it's better to
  invert the sense there, rather than in *every single use case*.
Then technically any 'other' branch isn't guaranteed to
This commit is contained in:
Athanasius 2022-10-02 12:11:16 +01:00
parent 5efd27a83c
commit baf62f03fd
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62
3 changed files with 17 additions and 15 deletions

View File

@ -454,19 +454,19 @@ def get_config(*args, **kwargs) -> AbstractConfig:
:param kwargs: Args to be passed through to implementation.
:return: Instance of the implementation.
"""
if sys.platform == "darwin": # pragma: sys-platform-not-darwin
if sys.platform == "darwin": # pragma: sys-platform-darwin
from .darwin import MacConfig
return MacConfig(*args, **kwargs)
elif sys.platform == "win32": # pragma: sys-platform-not-win32
elif sys.platform == "win32": # pragma: sys-platform-win32
from .windows import WinConfig
return WinConfig(*args, **kwargs)
elif sys.platform == "linux": # pragma: sys-platform-not-linux
elif sys.platform == "linux": # pragma: sys-platform-linux
from .linux import LinuxConfig
return LinuxConfig(*args, **kwargs)
else: # pragma: sys-platform-known
else: # pragma: sys-platform-not-known
raise ValueError(f'Unknown platform: {sys.platform=}')

View File

@ -94,7 +94,7 @@ class JournalLock:
:return: LockResult - See the class Enum definition
"""
if sys.platform == 'win32': # pragma: sys-platform-not-win32
if sys.platform == 'win32': # pragma: sys-platform-win32
logger.trace_if('journal-lock', 'win32, using msvcrt')
# win32 doesn't have fcntl, so we have to use msvcrt
import msvcrt
@ -107,7 +107,7 @@ class JournalLock:
f", assuming another process running: {e!r}")
return JournalLockResult.ALREADY_LOCKED
else: # pragma: sys-platform-win32
else: # pragma: sys-platform-not-win32
logger.trace_if('journal-lock', 'NOT win32, using fcntl')
try:
import fcntl
@ -143,7 +143,7 @@ class JournalLock:
return True # We weren't locked, and still aren't
unlocked = False
if sys.platform == 'win32': # pragma: sys-platform-not-win32
if sys.platform == 'win32': # pragma: sys-platform-win32
logger.trace_if('journal-lock', 'win32, using msvcrt')
# win32 doesn't have fcntl, so we have to use msvcrt
import msvcrt
@ -160,7 +160,7 @@ class JournalLock:
else:
unlocked = True
else: # pragma: sys-platform-win32
else: # pragma: sys-platform-not-win32
logger.trace_if('journal-lock', 'NOT win32, using fcntl')
try:
import fcntl

View File

@ -15,13 +15,15 @@ omit = [ "tests/*", "venv/*", "dist.win32/*" ]
plugins = [ "coverage_conditional_plugin" ]
[tool.coverage.coverage_conditional_plugin.rules]
sys-platform-win32 = "sys_platform == 'win32'"
sys-platform-not-win32 = "sys_platform != 'win32'"
sys-platform-darwin = "sys_platform == 'darwin'"
sys-platform-not-darwin = "sys_platform != 'darwin'"
sys-platform-linux = "sys_platform == 'linux'"
sys-platform-not-linux = "sys_platform != 'linux'"
sys-platform-known = "sys_platform in ('darwin', 'linux', 'win32')"
# Yes, the sense of all of these is inverted, because else it ends up
# inverted at *every* use.
sys-platform-win32 = "sys_platform != 'win32'"
sys-platform-not-win32 = "sys_platform == 'win32'"
sys-platform-darwin = "sys_platform != 'darwin'"
sys-platform-not-darwin = "sys_platform == 'darwin'"
sys-platform-linux = "sys_platform != 'linux'"
sys-platform-not-linux = "sys_platform == 'linux'"
sys-platform-not-known = "sys_platform in ('darwin', 'linux', 'win32')"
[tool.pyright]
# pythonPlatform = 'Darwin'