From ff88969aacfc4d9323283cdca5402408b162d2e4 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Thu, 25 Jul 2024 13:35:52 +0100 Subject: [PATCH 1/2] Fix interactive midi test_time with pytest test -s --- test/midi_test.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/midi_test.py b/test/midi_test.py index f4189a2351..6b5d7f5420 100644 --- a/test/midi_test.py +++ b/test/midi_test.py @@ -1,4 +1,5 @@ import unittest +import sys import pygame @@ -319,8 +320,14 @@ def test_get_init(self): def test_time(self): mtime = pygame.midi.time() self.assertIsInstance(mtime, int) - # should be close to 2-3... since the timer is just init'd. - self.assertTrue(0 <= mtime < 100) + if "pytest" in sys.modules: + # under pytest the midi module takes a couple of seconds to init + # instead of milliseconds + self.assertGreaterEqual(mtime, 0) + self.assertLess(mtime, 3000) + else: + self.assertGreaterEqual(mtime, 0) + self.assertLess(mtime, 100) class MidiModuleNonInteractiveTest(unittest.TestCase): From 8b8766b473b87918fcd6edfc53a1218715836440 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Sun, 29 Sep 2024 12:49:58 +0100 Subject: [PATCH 2/2] Fix stopping midi timer on midi.quit() & undo test changes --- src_c/cython/pygame/pypm.pyx | 2 ++ test/midi_test.py | 11 ++--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src_c/cython/pygame/pypm.pyx b/src_c/cython/pygame/pypm.pyx index d45e4aa9c0..8b47b89377 100644 --- a/src_c/cython/pygame/pypm.pyx +++ b/src_c/cython/pygame/pypm.pyx @@ -146,6 +146,7 @@ cdef extern from "porttime.h": ctypedef long PtTimestamp ctypedef void (* PtCallback)(PtTimestamp timestamp, void *userData) PtError Pt_Start(int resolution, PtCallback *callback, void *userData) + PtError Pt_Stop() PtTimestamp Pt_Time() cdef long _pypm_initialized @@ -171,6 +172,7 @@ def Terminate(): your system may crash. """ + Pt_Stop() Pm_Terminate() _pypm_initialized = 0 diff --git a/test/midi_test.py b/test/midi_test.py index 6b5d7f5420..f4189a2351 100644 --- a/test/midi_test.py +++ b/test/midi_test.py @@ -1,5 +1,4 @@ import unittest -import sys import pygame @@ -320,14 +319,8 @@ def test_get_init(self): def test_time(self): mtime = pygame.midi.time() self.assertIsInstance(mtime, int) - if "pytest" in sys.modules: - # under pytest the midi module takes a couple of seconds to init - # instead of milliseconds - self.assertGreaterEqual(mtime, 0) - self.assertLess(mtime, 3000) - else: - self.assertGreaterEqual(mtime, 0) - self.assertLess(mtime, 100) + # should be close to 2-3... since the timer is just init'd. + self.assertTrue(0 <= mtime < 100) class MidiModuleNonInteractiveTest(unittest.TestCase):