ajout de fichiers audio #123

Closed
opened 2023-09-29 18:22:14 +00:00 by ctactic · 1 comment
Collaborator

La commande sounds_monitor qui parcourt le disque en quête de nouveaux sons me donne :

AttributeError: 'Command' object has no attribute 'scan'

Le patch attaché rétablit le fonctionnement attendu chez moi.

J'ai pensé ajouter un test pour valider cette étape, mais ici plusieurs tests ne sont pas détectés en l'état par pytest parce que le nom des classes n'est pas préfixé par Test (si je m'y prends mal, pouvez-vous me montrer comment lancer les tests?)

--- a/aircox/tests/controllers/test_sound_monitor.py
+++ b/aircox/tests/controllers/test_sound_monitor.py
@@ -214,12 +214,14 @@ def monitor():
     yield sound_monitor.SoundMonitor()
 
 
-class SoundMonitor:
+class TestSoundMonitor:

https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#test-discovery

La commande *sounds_monitor* qui parcourt le disque en quête de nouveaux sons me donne : AttributeError: 'Command' object has no attribute 'scan' Le patch attaché rétablit le fonctionnement attendu chez moi. J'ai pensé ajouter un test pour valider cette étape, mais ici plusieurs tests ne sont pas détectés en l'état par pytest parce que le nom des classes n'est pas préfixé par *Test* (si je m'y prends mal, pouvez-vous me montrer comment lancer les tests?) ``` --- a/aircox/tests/controllers/test_sound_monitor.py +++ b/aircox/tests/controllers/test_sound_monitor.py @@ -214,12 +214,14 @@ def monitor(): yield sound_monitor.SoundMonitor() -class SoundMonitor: +class TestSoundMonitor: ``` https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#test-discovery
Author
Collaborator

Voici un patch pour ré-activer TestSoundMonitor, reste une erreur un peu complexe dont voici la trace au cas ou tu as 2 minutes:

____________________________________________ TestSoundMonitor.test_monitor ____________________________________________                                                                                                                                                [295/48237]
                                                                                                                                                                                                                                                                                  
self = <test_sound_monitor.TestSoundMonitor object at 0x7f02f7158c90>                                                                                                                                                                                                             
monitor = <aircox.controllers.sound_monitor.SoundMonitor object at 0x7f02f6bdd990>                                                                                                                                                                                                
monitor_interfaces = {'atexit': <aircox.test.Interface object at 0x7f02f6bdce50>, 'observer': <aircox.test.Interface object at 0x7f02f6bdcb10>}                                                                                                                                   
logger = <aircox.test.Interface object at 0x7f02f6bdd910>                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                  
    @pytest.mark.django_db                                                                                                                                                                                                                     
    def test_monitor(self, monitor, monitor_interfaces, logger):                                                                                                                                                                               
        def sleep(*args, **kwargs):                                                                                                                                                                                                            
            monitor.stop()                                                                                                                                                                                                                     
                                                                                                                                                                                                                                               
        time = Interface.inject(sound_monitor, "time", {"sleep": sleep})                                                                                                                                                                       
>       monitor.monitor(logger=logger)                                                                                                                                                                                                         
                                                                                                                                                                                                                                               
aircox/tests/controllers/test_sound_monitor.py:251:                                                                                                                                                                                            
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                                        
aircox/controllers/sound_monitor.py:318: in monitor                                                                         
    leave()                                                                                                                 
aircox/controllers/sound_monitor.py:308: in leave                                                                           
    observer.join()                                                                                                         
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                       
                                                                                                                            
self = <InotifyObserver(Thread-1, initial daemon)>, timeout = None                                                          
                                                                                                                                                                                                                                               
    def join(self, timeout=None):                                                                                           
        """Wait until the thread terminates.                                                                                
                                                                                                                            
        This blocks the calling thread until the thread whose join() method is                                              
        called terminates -- either normally or through an unhandled exception                                                                                                                                                                 
        or until the optional timeout occurs.                                                                               
                                                                                                                            
        When the timeout argument is present and not None, it should be a                                                   
        floating point number specifying a timeout for the operation in seconds                                             
        (or fractions thereof). As join() always returns None, you must call                                                
        is_alive() after join() to decide whether a timeout happened -- if the                                              
        thread is still alive, the join() call timed out.                                                                   
                                                                                                                            
        When the timeout argument is not present or None, the operation will                                                
        block until the thread terminates.                                                                                  
                                                                                                                            
        A thread can be join()ed many times.                                                                                
                                                                                                                            
        join() raises a RuntimeError if an attempt is made to join the current                                              
        thread as that would cause a deadlock. It is also an error to join() a                                              
        thread before it has been started and attempts to do so raises the same                                             
        exception.                                                                                                          
                                                                                                                            
        """                                                                                                                 
        if not self._initialized:                                                                                           
            raise RuntimeError("Thread.__init__() not called")                                                              
        if not self._started.is_set():                                                                                      
>           raise RuntimeError("cannot join thread before it is started")                                                   
E           RuntimeError: cannot join thread before it is started                                                           
                                                                                                                            
/usr/lib/python3.11/threading.py:1107: RuntimeError     
Voici un patch pour ré-activer TestSoundMonitor, reste une erreur un peu complexe dont voici la trace au cas ou tu as 2 minutes: ``` ____________________________________________ TestSoundMonitor.test_monitor ____________________________________________ [295/48237] self = <test_sound_monitor.TestSoundMonitor object at 0x7f02f7158c90> monitor = <aircox.controllers.sound_monitor.SoundMonitor object at 0x7f02f6bdd990> monitor_interfaces = {'atexit': <aircox.test.Interface object at 0x7f02f6bdce50>, 'observer': <aircox.test.Interface object at 0x7f02f6bdcb10>} logger = <aircox.test.Interface object at 0x7f02f6bdd910> @pytest.mark.django_db def test_monitor(self, monitor, monitor_interfaces, logger): def sleep(*args, **kwargs): monitor.stop() time = Interface.inject(sound_monitor, "time", {"sleep": sleep}) > monitor.monitor(logger=logger) aircox/tests/controllers/test_sound_monitor.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ aircox/controllers/sound_monitor.py:318: in monitor leave() aircox/controllers/sound_monitor.py:308: in leave observer.join() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <InotifyObserver(Thread-1, initial daemon)>, timeout = None def join(self, timeout=None): """Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates -- either normally or through an unhandled exception or until the optional timeout occurs. When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened -- if the thread is still alive, the join() call timed out. When the timeout argument is not present or None, the operation will block until the thread terminates. A thread can be join()ed many times. join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception. """ if not self._initialized: raise RuntimeError("Thread.__init__() not called") if not self._started.is_set(): > raise RuntimeError("cannot join thread before it is started") E RuntimeError: cannot join thread before it is started /usr/lib/python3.11/threading.py:1107: RuntimeError ```
thomas added the
bug
label 2023-10-02 14:12:35 +00:00
thomas added this to the 1.0 milestone 2023-10-11 10:01:57 +00:00
Sign in to join this conversation.
No description provided.