diff --git a/changes/2682.misc.rst b/changes/2682.misc.rst new file mode 100644 index 0000000000..758213cb09 --- /dev/null +++ b/changes/2682.misc.rst @@ -0,0 +1 @@ +An intermittent failure in macOS CI was corrected, and usage of Rubicon syntax was upgraded. diff --git a/cocoa/pyproject.toml b/cocoa/pyproject.toml index 049ff0507f..02af60649c 100644 --- a/cocoa/pyproject.toml +++ b/cocoa/pyproject.toml @@ -63,7 +63,7 @@ root = ".." [tool.setuptools_dynamic_dependencies] dependencies = [ "fonttools >= 4.42.1, < 5.0.0", - "rubicon-objc >= 0.4.7, < 0.5.0", + "rubicon-objc >= 0.4.9, < 0.5.0", "toga-core == {version}", ] diff --git a/cocoa/src/toga_cocoa/constraints.py b/cocoa/src/toga_cocoa/constraints.py index b0de131005..ca635a6301 100644 --- a/cocoa/src/toga_cocoa/constraints.py +++ b/cocoa/src/toga_cocoa/constraints.py @@ -62,47 +62,47 @@ def container(self, value): self._container = value if value is not None: # print(f"Add constraints for {self.widget} in {self.container} {self.widget.interface.layout}) - self.left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self.left_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeLeft, - NSLayoutRelationEqual, - self.container.native, - NSLayoutAttributeLeft, - 1.0, - 10, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeLeft, + relatedBy=NSLayoutRelationEqual, + toItem=self.container.native, + attribute__2=NSLayoutAttributeLeft, + multiplier=1.0, + constant=10, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.left_constraint) - self.top_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self.top_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeTop, - NSLayoutRelationEqual, - self.container.native, - NSLayoutAttributeTop, - 1.0, - 5, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeTop, + relatedBy=NSLayoutRelationEqual, + toItem=self.container.native, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=5, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.top_constraint) - self.width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self.width_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeRight, - NSLayoutRelationEqual, - self.widget.native, - NSLayoutAttributeLeft, - 1.0, - 50, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeRight, + relatedBy=NSLayoutRelationEqual, + toItem=self.widget.native, + attribute__2=NSLayoutAttributeLeft, + multiplier=1.0, + constant=50, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.width_constraint) - self.height_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 - self.widget.native, - NSLayoutAttributeBottom, - NSLayoutRelationEqual, + self.height_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeTop, - 1.0, - 30, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeBottom, + relatedBy=NSLayoutRelationEqual, + toItem=self.widget.native, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=30, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.height_constraint) diff --git a/cocoa/src/toga_cocoa/container.py b/cocoa/src/toga_cocoa/container.py index f612b291ac..8979114082 100644 --- a/cocoa/src/toga_cocoa/container.py +++ b/cocoa/src/toga_cocoa/container.py @@ -59,25 +59,25 @@ def __init__( # bigger. If the window is resizable, using >= allows the window to # be dragged larger; if not resizable, it enforces the smallest # size that can be programmatically set on the window. - self._min_width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self._min_width_constraint = NSLayoutConstraint.constraintWithItem( self.native, - NSLayoutAttributeRight, - NSLayoutRelationGreaterThanOrEqual, - self.native, - NSLayoutAttributeLeft, - 1.0, - min_width, + attribute__1=NSLayoutAttributeRight, + relatedBy=NSLayoutRelationGreaterThanOrEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeLeft, + multiplier=1.0, + constant=min_width, ).retain() self.native.addConstraint(self._min_width_constraint) - self._min_height_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 - self.native, - NSLayoutAttributeBottom, - NSLayoutRelationGreaterThanOrEqual, + self._min_height_constraint = NSLayoutConstraint.constraintWithItem( self.native, - NSLayoutAttributeTop, - 1.0, - min_height, + attribute__1=NSLayoutAttributeBottom, + relatedBy=NSLayoutRelationGreaterThanOrEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=min_height, ).retain() self.native.addConstraint(self._min_height_constraint) diff --git a/cocoa/src/toga_cocoa/widgets/internal/cells.py b/cocoa/src/toga_cocoa/widgets/internal/cells.py index f639254219..667c1c35d1 100644 --- a/cocoa/src/toga_cocoa/widgets/internal/cells.py +++ b/cocoa/src/toga_cocoa/widgets/internal/cells.py @@ -50,64 +50,64 @@ def setup(self): self.textField.translatesAutoresizingMaskIntoConstraints = False # center icon vertically in cell - self.iv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501 + self.iv_vertical_constraint = NSLayoutConstraint.constraintWithItem( self.imageView, - NSLayoutAttributeCenterY, - NSLayoutRelationEqual, - self, - NSLayoutAttributeCenterY, - 1, - 0, + attribute__1=NSLayoutAttributeCenterY, + relatedBy=NSLayoutRelationEqual, + toItem=self, + attribute__2=NSLayoutAttributeCenterY, + multiplier=1, + constant=0, ) # align left edge of icon with left edge of cell - self.iv_left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501 + self.iv_left_constraint = NSLayoutConstraint.constraintWithItem( self.imageView, - NSLayoutAttributeLeft, - NSLayoutRelationEqual, - self, - NSLayoutAttributeLeft, - 1, - 0, + attribute__1=NSLayoutAttributeLeft, + relatedBy=NSLayoutRelationEqual, + toItem=self, + attribute__2=NSLayoutAttributeLeft, + multiplier=1, + constant=0, ) # set fixed width of icon - self.iv_width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501 + self.iv_width_constraint = NSLayoutConstraint.constraintWithItem( self.imageView, - NSLayoutAttributeWidth, - NSLayoutRelationEqual, - None, - NSLayoutAttributeNotAnAttribute, - 1, - 16, + attribute__1=NSLayoutAttributeWidth, + relatedBy=NSLayoutRelationEqual, + toItem=None, + attribute__2=NSLayoutAttributeNotAnAttribute, + multiplier=1, + constant=6, ) # align text vertically in cell - self.tv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501 + self.tv_vertical_constraint = NSLayoutConstraint.constraintWithItem( self.textField, - NSLayoutAttributeCenterY, - NSLayoutRelationEqual, - self, - NSLayoutAttributeCenterY, - 1, - 0, + attribute__1=NSLayoutAttributeCenterY, + relatedBy=NSLayoutRelationEqual, + toItem=self, + attribute__2=NSLayoutAttributeCenterY, + multiplier=1, + constant=0, ) # align left edge of text with right edge of icon - self.tv_left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501 + self.tv_left_constraint = NSLayoutConstraint.constraintWithItem( self.textField, - NSLayoutAttributeLeft, - NSLayoutRelationEqual, - self.imageView, - NSLayoutAttributeRight, - 1, - 5, # 5 pixels padding between icon and text + attribute__1=NSLayoutAttributeLeft, + relatedBy=NSLayoutRelationEqual, + toItem=self.imageView, + attribute__2=NSLayoutAttributeRight, + multiplier=1, + constant=5, # 5 pixels padding between icon and text ) # align right edge of text with right edge of cell - self.tv_right_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501 + self.tv_right_constraint = NSLayoutConstraint.constraintWithItem( self.textField, - NSLayoutAttributeRight, - NSLayoutRelationEqual, - self, - NSLayoutAttributeRight, - 1, - -5, + attribute__1=NSLayoutAttributeRight, + relatedBy=NSLayoutRelationEqual, + toItem=self, + attribute__2=NSLayoutAttributeRight, + multiplier=1, + constant=-5, ) self.addConstraint(self.iv_vertical_constraint) diff --git a/cocoa/src/toga_cocoa/widgets/internal/refresh.py b/cocoa/src/toga_cocoa/widgets/internal/refresh.py index 1daf3ea5ab..39316f3617 100644 --- a/cocoa/src/toga_cocoa/widgets/internal/refresh.py +++ b/cocoa/src/toga_cocoa/widgets/internal/refresh.py @@ -193,58 +193,58 @@ def initWithDocument_(self, documentView): self.contentView.addSubview(self.refresh_view) # set layout constraints - indicatorHCenter = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + indicatorHCenter = NSLayoutConstraint.constraintWithItem( self.refresh_indicator, - NSLayoutAttributeCenterX, - NSLayoutRelationEqual, - self.refresh_view, - NSLayoutAttributeCenterX, - 1.0, - 0, + attribute__1=NSLayoutAttributeCenterX, + relatedBy=NSLayoutRelationEqual, + toItem=self.refresh_view, + attribute__2=NSLayoutAttributeCenterX, + multiplier=1.0, + constant=0, ) self.refresh_view.addConstraint(indicatorHCenter) - indicatorVCenter = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + indicatorVCenter = NSLayoutConstraint.constraintWithItem( self.refresh_indicator, - NSLayoutAttributeCenterY, - NSLayoutRelationEqual, - self.refresh_view, - NSLayoutAttributeCenterY, - 1.0, - 0, + attribute__1=NSLayoutAttributeCenterY, + relatedBy=NSLayoutRelationEqual, + toItem=self.refresh_view, + attribute__2=NSLayoutAttributeCenterY, + multiplier=1.0, + constant=0, ) self.refresh_view.addConstraint(indicatorVCenter) - refreshWidth = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + refreshWidth = NSLayoutConstraint.constraintWithItem( self.refresh_view, - NSLayoutAttributeWidth, - NSLayoutRelationEqual, - self.contentView, - NSLayoutAttributeWidth, - 1.0, - 0, + attribute__1=NSLayoutAttributeWidth, + relatedBy=NSLayoutRelationEqual, + toItem=self.contentView, + attribute__2=NSLayoutAttributeWidth, + multiplier=1.0, + constant=0, ) self.contentView.addConstraint(refreshWidth) - refreshHeight = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + refreshHeight = NSLayoutConstraint.constraintWithItem( self.refresh_view, - NSLayoutAttributeHeight, - NSLayoutRelationEqual, - None, - NSLayoutAttributeNotAnAttribute, - 1.0, - HEADER_HEIGHT, + attribute__1=NSLayoutAttributeHeight, + relatedBy=NSLayoutRelationEqual, + toItem=None, + attribute__2=NSLayoutAttributeNotAnAttribute, + multiplier=1.0, + constant=HEADER_HEIGHT, ) self.contentView.addConstraint(refreshHeight) - refreshHeight = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + refreshHeight = NSLayoutConstraint.constraintWithItem( self.refresh_view, - NSLayoutAttributeTop, - NSLayoutRelationEqual, - self.contentView, - NSLayoutAttributeTop, - 1.0, - -HEADER_HEIGHT, + attribute__1=NSLayoutAttributeTop, + relatedBy=NSLayoutRelationEqual, + toItem=self.contentView, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=-HEADER_HEIGHT, ) self.contentView.addConstraint(refreshHeight) diff --git a/cocoa/src/toga_cocoa/widgets/textinput.py b/cocoa/src/toga_cocoa/widgets/textinput.py index 43f3449fcd..2de4fd10f7 100644 --- a/cocoa/src/toga_cocoa/widgets/textinput.py +++ b/cocoa/src/toga_cocoa/widgets/textinput.py @@ -124,32 +124,32 @@ def add_error_label(self): self.error_label.textColor = NSColor.systemRedColor self.native.addSubview(self.error_label) - leading_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + leading_constraint = NSLayoutConstraint.constraintWithItem( self.native, - NSLayoutAttributeLeading, - NSLayoutRelationEqual, - self.error_label, - NSLayoutAttributeLeading, - 1.0, - 4.0, + attribute__1=NSLayoutAttributeLeading, + relatedBy=NSLayoutRelationEqual, + toItem=self.error_label, + attribute__2=NSLayoutAttributeLeading, + multiplier=1.0, + constant=4.0, ) - trailing_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + trailing_constraint = NSLayoutConstraint.constraintWithItem( self.native, - NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self.error_label, - NSLayoutAttributeTrailing, - 1.0, - 4.0, + attribute__1=NSLayoutAttributeTrailing, + relatedBy=NSLayoutRelationEqual, + toItem=self.error_label, + attribute__2=NSLayoutAttributeTrailing, + multiplier=1.0, + constant=4.0, ) - center_y_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + center_y_constraint = NSLayoutConstraint.constraintWithItem( self.error_label, - NSLayoutAttributeCenterY, - NSLayoutRelationEqual, - self.native, - NSLayoutAttributeCenterY, - 1.0, - 0.0, + attribute__1=NSLayoutAttributeCenterY, + relatedBy=NSLayoutRelationEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeCenterY, + multiplier=1.0, + constant=0.0, ) self.native.addConstraints( [ diff --git a/iOS/pyproject.toml b/iOS/pyproject.toml index 600f2b4388..c98fadf6dc 100644 --- a/iOS/pyproject.toml +++ b/iOS/pyproject.toml @@ -62,7 +62,7 @@ root = ".." [tool.setuptools_dynamic_dependencies] dependencies = [ "fonttools >= 4.42.1, < 5.0.0", - "rubicon-objc >= 0.4.7, < 0.5.0", + "rubicon-objc >= 0.4.9, < 0.5.0", "toga-core == {version}", ] diff --git a/iOS/src/toga_iOS/constraints.py b/iOS/src/toga_iOS/constraints.py index d78be11722..dc3e4df076 100644 --- a/iOS/src/toga_iOS/constraints.py +++ b/iOS/src/toga_iOS/constraints.py @@ -57,47 +57,47 @@ def container(self, value): self._container = value if value is not None: # print(f"Add constraints for {self.widget} in {self.container} {self.widget.interface.layout}") - self.left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self.left_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeLeft, - NSLayoutRelationEqual, - self.container.native, - NSLayoutAttributeLeft, - 1.0, - 10, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeLeft, + relatedBy=NSLayoutRelationEqual, + toItem=self.container.native, + attribute__2=NSLayoutAttributeLeft, + multiplier=1.0, + constant=10, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.left_constraint) - self.top_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self.top_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeTop, - NSLayoutRelationEqual, - self.container.native, - NSLayoutAttributeTop, - 1.0, - 5, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeTop, + relatedBy=NSLayoutRelationEqual, + toItem=self.container.native, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=5, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.top_constraint) - self.width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + self.width_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeRight, - NSLayoutRelationEqual, - self.widget.native, - NSLayoutAttributeLeft, - 1.0, - 50, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeRight, + relatedBy=NSLayoutRelationEqual, + toItem=self.widget.native, + attribute__2=NSLayoutAttributeLeft, + multiplier=1.0, + constant=50, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.width_constraint) - self.height_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 - self.widget.native, - NSLayoutAttributeBottom, - NSLayoutRelationEqual, + self.height_constraint = NSLayoutConstraint.constraintWithItem( self.widget.native, - NSLayoutAttributeTop, - 1.0, - 30, # Use a dummy, non-zero value for now + attribute__1=NSLayoutAttributeBottom, + relatedBy=NSLayoutRelationEqual, + toItem=self.widget.native, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=30, # Use a dummy, non-zero value for now ).retain() self.container.native.addConstraint(self.height_constraint) diff --git a/iOS/src/toga_iOS/widgets/multilinetextinput.py b/iOS/src/toga_iOS/widgets/multilinetextinput.py index 600dbfb60d..9959712e6f 100644 --- a/iOS/src/toga_iOS/widgets/multilinetextinput.py +++ b/iOS/src/toga_iOS/widgets/multilinetextinput.py @@ -76,41 +76,41 @@ def create(self): self.add_constraints() def constrain_placeholder_label(self): - leading_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + leading_constraint = NSLayoutConstraint.constraintWithItem( self.placeholder_label, - NSLayoutAttributeLeading, - NSLayoutRelationEqual, - self.native, - NSLayoutAttributeLeading, - 1.0, - 4.0, + attribute__1=NSLayoutAttributeLeading, + relatedBy=NSLayoutRelationEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeLeading, + multiplier=1.0, + constant=4.0, ) - trailing_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + trailing_constraint = NSLayoutConstraint.constraintWithItem( self.placeholder_label, - NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self.native, - NSLayoutAttributeTrailing, - 1.0, - 0, + attribute__1=NSLayoutAttributeTrailing, + relatedBy=NSLayoutRelationEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeTrailing, + multiplier=1.0, + constant=0, ) - top_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + top_constraint = NSLayoutConstraint.constraintWithItem( self.placeholder_label, - NSLayoutAttributeTop, - NSLayoutRelationEqual, - self.native, - NSLayoutAttributeTop, - 1.0, - 8.0, + attribute__1=NSLayoutAttributeTop, + relatedBy=NSLayoutRelationEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeTop, + multiplier=1.0, + constant=8.0, ) - bottom_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + bottom_constraint = NSLayoutConstraint.constraintWithItem( self.placeholder_label, - NSLayoutAttributeBottom, - NSLayoutRelationEqual, - self.native, - NSLayoutAttributeBottom, - 1.0, - 0, + attribute__1=NSLayoutAttributeBottom, + relatedBy=NSLayoutRelationEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeBottom, + multiplier=1.0, + constant=0, ) self.native.addConstraints( [leading_constraint, trailing_constraint, top_constraint, bottom_constraint] diff --git a/iOS/src/toga_iOS/widgets/textinput.py b/iOS/src/toga_iOS/widgets/textinput.py index b9e2875404..2397249bf7 100644 --- a/iOS/src/toga_iOS/widgets/textinput.py +++ b/iOS/src/toga_iOS/widgets/textinput.py @@ -73,32 +73,32 @@ def add_error_label(self): self.error_label.textColor = UIColor.redColor self.native.addSubview(self.error_label) - leading_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + leading_constraint = NSLayoutConstraint.constraintWithItem( self.native, - NSLayoutAttributeLeading, - NSLayoutRelationEqual, - self.error_label, - NSLayoutAttributeLeading, - 1.0, - 8.0, + attribute__1=NSLayoutAttributeLeading, + relatedBy=NSLayoutRelationEqual, + toItem=self.error_label, + attribute__2=NSLayoutAttributeLeading, + multiplier=1.0, + constant=8.0, ) - trailing_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + trailing_constraint = NSLayoutConstraint.constraintWithItem( self.native, - NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self.error_label, - NSLayoutAttributeTrailing, - 1.0, - 8.0, + attribute__1=NSLayoutAttributeTrailing, + relatedBy=NSLayoutRelationEqual, + toItem=self.error_label, + attribute__2=NSLayoutAttributeTrailing, + multiplier=1.0, + constant=8.0, ) - center_y_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501 + center_y_constraint = NSLayoutConstraint.constraintWithItem( self.error_label, - NSLayoutAttributeCenterY, - NSLayoutRelationEqual, - self.native, - NSLayoutAttributeCenterY, - 1.0, - 0.0, + attribute__1=NSLayoutAttributeCenterY, + relatedBy=NSLayoutRelationEqual, + toItem=self.native, + attribute__2=NSLayoutAttributeCenterY, + multiplier=1.0, + constant=0.0, ) self.native.addConstraints( [ diff --git a/testbed/tests/conftest.py b/testbed/tests/conftest.py index 057d4175d3..aa021ae0ba 100644 --- a/testbed/tests/conftest.py +++ b/testbed/tests/conftest.py @@ -1,4 +1,5 @@ import asyncio +import gc import inspect from dataclasses import dataclass from importlib import import_module @@ -46,12 +47,37 @@ async def app_probe(app): print("\nConstructing app probe") yield probe + # Force a GC pass on the main thread. This isn't perfect, but it helps + # minimize garbage collection on the test thread. + gc.collect() + @fixture(scope="session") def main_window(app): return app.main_window +@fixture(autouse=True) +async def window_cleanup(app, main_window): + # Ensure that at the end of every test, all windows that aren't the + # main window have been closed and deleted. This needs to be done in + # 2 passes because we can't modify the list while iterating over it. + kill_list = [] + for window in app.windows: + if window != main_window: + kill_list.append(window) + + # Then purge everything on the kill list. + while kill_list: + window = kill_list.pop() + window.close() + del window + + # Force a GC pass on the main thread. This isn't perfect, but it helps + # minimize garbage collection on the test thread. + gc.collect() + + @fixture(scope="session") async def main_window_probe(app, main_window): old_content = main_window.content diff --git a/testbed/tests/testbed.py b/testbed/tests/testbed.py index 8b6423e068..23a262b1e1 100644 --- a/testbed/tests/testbed.py +++ b/testbed/tests/testbed.py @@ -15,10 +15,27 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci): try: - # Wait for the app's main window to be visible. + # Wait for the app's main window to be visible. Retrieving the actual main window + # will raise an exception until the app is actually initialized. print("Waiting for app to be ready for testing... ", end="", flush=True) - while app.main_window is None or not app.main_window.visible: + i = 0 + ready = False + while i < 100 and not ready: + try: + main_window = app.main_window + if main_window.visible: + ready = True + except ValueError: + pass + time.sleep(0.05) + i += 1 + + if not ready: + print("\nApp didn't display a main window.") + app.returncode = 1 + return + print("ready.") # Control the run speed of the test app. app.run_slow = run_slow