#538 [python] fix wait function for custom List
Merged 5 years ago by dturecek. Opened 5 years ago by frostyx.
copr/ frostyx/copr fix-wait  into  master

@@ -1,7 +1,7 @@ 

  import pytest

  import mock

  from munch import Munch

- from copr.v3.helpers import wait, succeeded

+ from copr.v3.helpers import wait, succeeded, List

  from copr.v3 import BuildProxy, CoprException

  

  
@@ -37,6 +37,12 @@ 

          mock_get.side_effect = lambda id: builds[id-1]

          assert wait(builds)

  

+     @mock.patch("copr.v3.proxies.build.BuildProxy.get")

+     def test_wait_custom_list(self, mock_get):

+         builds = List([Munch(id=1, state="succeeded"), Munch(id=2, state="failed")], proxy=BuildProxy({}))

+         mock_get.side_effect = lambda self, id: builds[id-1]

+         assert wait(builds)

+ 

      @mock.patch("time.time")

      @mock.patch("copr.v3.proxies.build.BuildProxy.get")

      def test_wait_timeout(self, mock_get, mock_time):

file modified
+7 -2
@@ -82,7 +82,7 @@ 

          wait([build1, build2])

  

      """

-     builds = waitable if type(waitable) == list else [waitable]

+     builds = waitable if isinstance(waitable, list) else [waitable]

      watched = set([build.id for build in builds])

      munches = dict((build.id, build) for build in builds)

      failed = []
@@ -90,7 +90,12 @@ 

  

      while True:

          for build_id in watched.copy():

-             build = munches[build_id] = munches[build_id].__proxy__.get(build_id)

+             if hasattr(munches[build_id], "__proxy__"):

+                 proxy = munches[build_id].__proxy__

+             else:

+                 proxy = waitable.__proxy__

+             build = munches[build_id] = proxy.get(build_id)

+ 

              if build.state in ["failed"]:

                  failed.append(build_id)

              if build.state in ["succeeded", "skipped", "failed", "canceled"]:

The wait function is supposed to work with on waitable instances.
It should work on a Munch returned by other API method (i.e. it has
a __proxy__ property), or list of such munches.

It should also work on a helpers.List of Munch objects returned
by some API method. In such case, we set the __proxy__ property
to the List not munches themselves.

Should be rather isinstance(waitable, (list, List)

rebased onto 79acf8fedd9f67e5c8578be539e040180dc9c646

5 years ago

rebased onto 09f7dad

5 years ago

Pull-Request has been merged by dturecek

5 years ago