Convert not_implemented to use a warning subclass.

This commit is contained in:
Russell Keith-Magee 2024-02-15 08:50:08 +08:00
parent 71cd314f56
commit 869e4ca6a6
No known key found for this signature in database
GPG key ID: 3D2DAB6A37BB5BC3
9 changed files with 38 additions and 8 deletions

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, MainWindow
from .command import Command
@ -31,7 +33,7 @@ from .window import Window
def not_implemented(feature):
print(f"[Android] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("Android", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, DocumentApp, MainWindow
from .command import Command
@ -35,7 +37,7 @@ from .window import Window
def not_implemented(feature):
print(f"[Cocoa] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("Cocoa", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
import warnings
from .app import App, DocumentApp, DocumentMainWindow, MainWindow
# Resources
@ -37,7 +39,19 @@ from .widgets.tree import Tree
from .widgets.webview import WebView
from .window import Window
class NotImplementedWarning(RuntimeWarning):
# pytest.warns() requires that Warning() subclasses are constructed by passing a
# single argument (the warning message). Use a factory method to avoid reproducing
# the message format and the warn invocation.
@classmethod
def warn(self, platform, feature):
"""Raise a warning that a feature isn't implemented on a platform."""
warnings.warn(NotImplementedWarning(f"[{platform}] Not implemented: {feature}"))
__all__ = [
"NotImplementedWarning",
# Applications
"App",
"DocumentApp",

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, DocumentApp, MainWindow
from .command import Command
@ -36,7 +38,7 @@ from .window import Window
def not_implemented(feature):
raise NotImplementedError()
NotImplementedWarning.warn("Dummy", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, DocumentApp, MainWindow
from .command import Command
@ -32,7 +34,7 @@ from .window import Window
def not_implemented(feature):
print(f"[GTK+] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("GTK", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, MainWindow
from .colors import native_color
@ -36,7 +38,7 @@ from .window import Window
def not_implemented(feature):
print(f"[iOS] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("iOS", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, DocumentApp, MainWindow
@ -41,7 +43,7 @@ from .window import Window
def not_implemented(feature):
print(f"[Textual] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("Textual", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, MainWindow # DocumentApp
from .command import Command
@ -39,7 +41,7 @@ from .widgets.textinput import TextInput
def not_implemented(feature):
print(f"[Web] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("Web", feature) # pragma: nocover
__all__ = [

View file

@ -1,3 +1,5 @@
from toga import NotImplementedWarning
from . import dialogs
from .app import App, MainWindow
from .command import Command
@ -31,7 +33,7 @@ from .window import Window
def not_implemented(feature):
print(f"[Winforms] Not implemented: {feature}") # pragma: nocover
NotImplementedWarning.warn("Winforms", feature) # pragma: nocover
__all__ = [