Skip to content

Commit

Permalink
Fix infinite recursion.
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorSMarks committed Jul 23, 2021
1 parent 7c31c93 commit 849e5f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

if isTravis and system == 'Windows':
print('\n>>> Will be mocking instead of using the real MciSendStringW function for most tests.\n')
from ctypes import windll
originalMCISendStringW = windll.winmm.mciSendStringW
try:
from unittest.mock import patch
except ImportError:
Expand All @@ -30,7 +32,6 @@
# the library available on pypi.
pipmain(['install', 'mock==2.0.0'])
from mock import patch
from ctypes import windll

from playsound import playsound, PlaysoundException
import unittest
Expand All @@ -44,18 +45,18 @@ def mockMciSendStringW(command, buf, bufLen, bufStart):
decodeCommand = command.decode('utf-16')

if decodeCommand.startswith(u'open '):
testCase.assertEqual(windll.winmm.mciSendStringW(command, buf, bufLen, bufStart), 306) # 306 indicates drivers are missing. It's fine.
testCase.assertIn(originalMCISendStringW(command, buf, bufLen, bufStart), [0, 306]) # 306 indicates drivers are missing. It's fine.
return 0

if decodeCommand.endswith(u' wait'):
testCase.assertEqual(windll.winmm.mciSendStringW(command, buf, bufLen, bufStart), 0)
testCase.assertEqual(originalMCISendStringW(command, buf, bufLen, bufStart), 0)
sleep(expectedDuration)
return 0

if decodeCommand.startswith(u'close '):
global sawClose
sawClose = True
testCase.assertEqual(windll.winmm.mciSendStringW(command, buf, bufLen, bufStart), 0)
testCase.assertEqual(originalMCISendStringW(command, buf, bufLen, bufStart), 0)
return 0

class PlaysoundTests(unittest.TestCase):
Expand Down

0 comments on commit 849e5f8

Please sign in to comment.