[libcamera-devel,v2,06/13] py: unittests: make typechecker happy
diff mbox series

Message ID 20220517143325.71784-7-tomi.valkeinen@ideasonboard.com
State Superseded
Headers show
Series
  • Misc Python bindings patches
Related show

Commit Message

Tomi Valkeinen May 17, 2022, 2:33 p.m. UTC
Add some annotations and self.assertIsNotNone() calls to remove the
typechecker warnings.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 test/py/unittests.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart May 17, 2022, 4:08 p.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Tue, May 17, 2022 at 05:33:18PM +0300, Tomi Valkeinen wrote:
> Add some annotations and self.assertIsNotNone() calls to remove the
> typechecker warnings.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  test/py/unittests.py | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/test/py/unittests.py b/test/py/unittests.py
> index 4c214f0a..2ea5ca35 100755
> --- a/test/py/unittests.py
> +++ b/test/py/unittests.py
> @@ -10,6 +10,7 @@ import libcamera as libcam
>  import os
>  import selectors
>  import time
> +import typing
>  import unittest
>  import weakref
>  
> @@ -70,6 +71,9 @@ class SimpleTestMethods(BaseTestCase):
>  
>  
>  class CameraTesterBase(BaseTestCase):
> +    cm: typing.Any
> +    cam: typing.Any
> +
>      def setUp(self):
>          self.cm = libcam.CameraManager.singleton()
>          self.cam = next((cam for cam in self.cm.cameras if 'platform/vimc' in cam.id), None)
> @@ -131,6 +135,7 @@ class AllocatorTestMethods(CameraTesterBase):
>          wr_allocator = weakref.ref(allocator)
>  
>          buffers = allocator.buffers(stream)
> +        self.assertIsNotNone(buffers)
>          buffers = None
>  
>          buffer = allocator.buffers(stream)[0]
> @@ -166,6 +171,8 @@ class SimpleCaptureMethods(CameraTesterBase):
>  
>          streamconfig = camconfig.at(0)
>          fmts = streamconfig.formats
> +        self.assertIsNotNone(fmts)
> +        fmts = None
>  
>          ret = cam.configure(camconfig)
>          self.assertZero(ret)
> @@ -225,6 +232,7 @@ class SimpleCaptureMethods(CameraTesterBase):
>  
>          streamconfig = camconfig.at(0)
>          fmts = streamconfig.formats
> +        self.assertIsNotNone(fmts)

Is there a reason why there's no fmts = None here ? Apart from that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>          ret = cam.configure(camconfig)
>          self.assertZero(ret)
> @@ -348,9 +356,9 @@ if __name__ == '__main__':
>          gc.unfreeze()
>          gc.collect()
>  
> -        obs_after = get_all_objects([obs_before])
> +        obs_after = get_all_objects([obs_before])   # type: ignore
>  
> -        before = create_type_count_map(obs_before)
> +        before = create_type_count_map(obs_before)  # type: ignore
>          after = create_type_count_map(obs_after)
>  
>          leaks = diff_type_count_maps(before, after)
Kieran Bingham May 17, 2022, 4:51 p.m. UTC | #2
Quoting Laurent Pinchart (2022-05-17 17:08:25)
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Tue, May 17, 2022 at 05:33:18PM +0300, Tomi Valkeinen wrote:
> > Add some annotations and self.assertIsNotNone() calls to remove the
> > typechecker warnings.
> > 

Are pyright and typechecker external commands that we need to introduce
as part of our integration tests to verify commits now?

Aside from Laurent's question...

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> > ---
> >  test/py/unittests.py | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/test/py/unittests.py b/test/py/unittests.py
> > index 4c214f0a..2ea5ca35 100755
> > --- a/test/py/unittests.py
> > +++ b/test/py/unittests.py
> > @@ -10,6 +10,7 @@ import libcamera as libcam
> >  import os
> >  import selectors
> >  import time
> > +import typing
> >  import unittest
> >  import weakref
> >  
> > @@ -70,6 +71,9 @@ class SimpleTestMethods(BaseTestCase):
> >  
> >  
> >  class CameraTesterBase(BaseTestCase):
> > +    cm: typing.Any
> > +    cam: typing.Any
> > +
> >      def setUp(self):
> >          self.cm = libcam.CameraManager.singleton()
> >          self.cam = next((cam for cam in self.cm.cameras if 'platform/vimc' in cam.id), None)
> > @@ -131,6 +135,7 @@ class AllocatorTestMethods(CameraTesterBase):
> >          wr_allocator = weakref.ref(allocator)
> >  
> >          buffers = allocator.buffers(stream)
> > +        self.assertIsNotNone(buffers)
> >          buffers = None
> >  
> >          buffer = allocator.buffers(stream)[0]
> > @@ -166,6 +171,8 @@ class SimpleCaptureMethods(CameraTesterBase):
> >  
> >          streamconfig = camconfig.at(0)
> >          fmts = streamconfig.formats
> > +        self.assertIsNotNone(fmts)
> > +        fmts = None
> >  
> >          ret = cam.configure(camconfig)
> >          self.assertZero(ret)
> > @@ -225,6 +232,7 @@ class SimpleCaptureMethods(CameraTesterBase):
> >  
> >          streamconfig = camconfig.at(0)
> >          fmts = streamconfig.formats
> > +        self.assertIsNotNone(fmts)
> 
> Is there a reason why there's no fmts = None here ? Apart from that,
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> >  
> >          ret = cam.configure(camconfig)
> >          self.assertZero(ret)
> > @@ -348,9 +356,9 @@ if __name__ == '__main__':
> >          gc.unfreeze()
> >          gc.collect()
> >  
> > -        obs_after = get_all_objects([obs_before])
> > +        obs_after = get_all_objects([obs_before])   # type: ignore
> >  
> > -        before = create_type_count_map(obs_before)
> > +        before = create_type_count_map(obs_before)  # type: ignore
> >          after = create_type_count_map(obs_after)
> >  
> >          leaks = diff_type_count_maps(before, after)
> 
> -- 
> Regards,
> 
> Laurent Pinchart
Tomi Valkeinen May 18, 2022, 6:46 a.m. UTC | #3
On 17/05/2022 19:08, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Tue, May 17, 2022 at 05:33:18PM +0300, Tomi Valkeinen wrote:
>> Add some annotations and self.assertIsNotNone() calls to remove the
>> typechecker warnings.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   test/py/unittests.py | 12 ++++++++++--
>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/test/py/unittests.py b/test/py/unittests.py
>> index 4c214f0a..2ea5ca35 100755
>> --- a/test/py/unittests.py
>> +++ b/test/py/unittests.py
>> @@ -10,6 +10,7 @@ import libcamera as libcam
>>   import os
>>   import selectors
>>   import time
>> +import typing
>>   import unittest
>>   import weakref
>>   
>> @@ -70,6 +71,9 @@ class SimpleTestMethods(BaseTestCase):
>>   
>>   
>>   class CameraTesterBase(BaseTestCase):
>> +    cm: typing.Any
>> +    cam: typing.Any
>> +
>>       def setUp(self):
>>           self.cm = libcam.CameraManager.singleton()
>>           self.cam = next((cam for cam in self.cm.cameras if 'platform/vimc' in cam.id), None)
>> @@ -131,6 +135,7 @@ class AllocatorTestMethods(CameraTesterBase):
>>           wr_allocator = weakref.ref(allocator)
>>   
>>           buffers = allocator.buffers(stream)
>> +        self.assertIsNotNone(buffers)
>>           buffers = None
>>   
>>           buffer = allocator.buffers(stream)[0]
>> @@ -166,6 +171,8 @@ class SimpleCaptureMethods(CameraTesterBase):
>>   
>>           streamconfig = camconfig.at(0)
>>           fmts = streamconfig.formats
>> +        self.assertIsNotNone(fmts)
>> +        fmts = None
>>   
>>           ret = cam.configure(camconfig)
>>           self.assertZero(ret)
>> @@ -225,6 +232,7 @@ class SimpleCaptureMethods(CameraTesterBase):
>>   
>>           streamconfig = camconfig.at(0)
>>           fmts = streamconfig.formats
>> +        self.assertIsNotNone(fmts)
> 
> Is there a reason why there's no fmts = None here ? Apart from that,

No, I can add it.

  Tomi
Tomi Valkeinen May 18, 2022, 6:51 a.m. UTC | #4
On 17/05/2022 19:51, Kieran Bingham wrote:
> Quoting Laurent Pinchart (2022-05-17 17:08:25)
>> Hi Tomi,
>>
>> Thank you for the patch.
>>
>> On Tue, May 17, 2022 at 05:33:18PM +0300, Tomi Valkeinen wrote:
>>> Add some annotations and self.assertIsNotNone() calls to remove the
>>> typechecker warnings.
>>>
> 
> Are pyright and typechecker external commands that we need to introduce
> as part of our integration tests to verify commits now?

pyright is the typechecker I use, or my editor uses. I'm not familiar 
with the internals, seems to be some horrible contraption with node.js 
and whatnots...

A Python static typechecker to verify the commits would be nice, 
although at least pyright seems to complain about lots of unnecessary 
things. But I presume adjusting the settings would give us something 
usable. I have to admit I'm pretty clueless about those, though.

  Tomi

Patch
diff mbox series

diff --git a/test/py/unittests.py b/test/py/unittests.py
index 4c214f0a..2ea5ca35 100755
--- a/test/py/unittests.py
+++ b/test/py/unittests.py
@@ -10,6 +10,7 @@  import libcamera as libcam
 import os
 import selectors
 import time
+import typing
 import unittest
 import weakref
 
@@ -70,6 +71,9 @@  class SimpleTestMethods(BaseTestCase):
 
 
 class CameraTesterBase(BaseTestCase):
+    cm: typing.Any
+    cam: typing.Any
+
     def setUp(self):
         self.cm = libcam.CameraManager.singleton()
         self.cam = next((cam for cam in self.cm.cameras if 'platform/vimc' in cam.id), None)
@@ -131,6 +135,7 @@  class AllocatorTestMethods(CameraTesterBase):
         wr_allocator = weakref.ref(allocator)
 
         buffers = allocator.buffers(stream)
+        self.assertIsNotNone(buffers)
         buffers = None
 
         buffer = allocator.buffers(stream)[0]
@@ -166,6 +171,8 @@  class SimpleCaptureMethods(CameraTesterBase):
 
         streamconfig = camconfig.at(0)
         fmts = streamconfig.formats
+        self.assertIsNotNone(fmts)
+        fmts = None
 
         ret = cam.configure(camconfig)
         self.assertZero(ret)
@@ -225,6 +232,7 @@  class SimpleCaptureMethods(CameraTesterBase):
 
         streamconfig = camconfig.at(0)
         fmts = streamconfig.formats
+        self.assertIsNotNone(fmts)
 
         ret = cam.configure(camconfig)
         self.assertZero(ret)
@@ -348,9 +356,9 @@  if __name__ == '__main__':
         gc.unfreeze()
         gc.collect()
 
-        obs_after = get_all_objects([obs_before])
+        obs_after = get_all_objects([obs_before])   # type: ignore
 
-        before = create_type_count_map(obs_before)
+        before = create_type_count_map(obs_before)  # type: ignore
         after = create_type_count_map(obs_after)
 
         leaks = diff_type_count_maps(before, after)