Skip to content

Commit

Permalink
[tests] use assertInstance(obj, K) not assertTrue(isinstance(obj, K))
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed Apr 4, 2022
1 parent fa8f6dc commit 6a0654d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 66 deletions.
20 changes: 10 additions & 10 deletions tests/test_contrib_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ async def test_audio_stop_consumer(self):
exc1, frame2 = await asyncio.gather(
proxy1.recv(), proxy2.recv(), return_exceptions=True
)
self.assertTrue(isinstance(exc1, MediaStreamError))
self.assertTrue(isinstance(frame2, av.AudioFrame))
self.assertIsInstance(exc1, MediaStreamError)
self.assertIsInstance(frame2, av.AudioFrame)

# stop source track
source.stop()
Expand Down Expand Up @@ -224,8 +224,8 @@ async def test_audio_stop_consumer_unbuffered(self):
exc1, frame2 = await asyncio.gather(
proxy1.recv(), proxy2.recv(), return_exceptions=True
)
self.assertTrue(isinstance(exc1, MediaStreamError))
self.assertTrue(isinstance(frame2, av.AudioFrame))
self.assertIsInstance(exc1, MediaStreamError)
self.assertIsInstance(frame2, av.AudioFrame)

# stop source track
source.stop()
Expand Down Expand Up @@ -261,8 +261,8 @@ async def test_audio_stop_source(self):
exc1, exc2 = await asyncio.gather(
proxy1.recv(), proxy2.recv(), return_exceptions=True
)
self.assertTrue(isinstance(exc1, MediaStreamError))
self.assertTrue(isinstance(exc2, MediaStreamError))
self.assertIsInstance(exc1, MediaStreamError)
self.assertIsInstance(exc2, MediaStreamError)

@asynctest
async def test_audio_stop_source_unbuffered(self):
Expand Down Expand Up @@ -294,8 +294,8 @@ async def test_audio_stop_source_unbuffered(self):
exc1, exc2 = await asyncio.gather(
proxy1.recv(), proxy2.recv(), return_exceptions=True
)
self.assertTrue(isinstance(exc1, MediaStreamError))
self.assertTrue(isinstance(exc2, MediaStreamError))
self.assertIsInstance(exc1, MediaStreamError)
self.assertIsInstance(exc2, MediaStreamError)

@asynctest
async def test_audio_slow_consumer(self):
Expand Down Expand Up @@ -342,8 +342,8 @@ async def test_audio_slow_consumer(self):
exc1, frame2 = await asyncio.gather(
proxy1.recv(), proxy2.recv(), return_exceptions=True
)
self.assertTrue(isinstance(exc1, MediaStreamError))
self.assertTrue(isinstance(frame2, av.AudioFrame))
self.assertIsInstance(exc1, MediaStreamError)
self.assertIsInstance(frame2, av.AudioFrame)

# stop source track
source.stop()
Expand Down
16 changes: 8 additions & 8 deletions tests/test_g711.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PcmaTest(CodecTestCase):
def test_decoder(self):
decoder = get_decoder(PCMA_CODEC)
self.assertTrue(isinstance(decoder, PcmaDecoder))
self.assertIsInstance(decoder, PcmaDecoder)

frames = decoder.decode(JitterFrame(data=b"\xd5" * 160, timestamp=0))
self.assertEqual(len(frames), 1)
Expand All @@ -29,7 +29,7 @@ def test_decoder(self):

def test_encoder_mono_8hz(self):
encoder = get_encoder(PCMA_CODEC)
self.assertTrue(isinstance(encoder, PcmaEncoder))
self.assertIsInstance(encoder, PcmaEncoder)

for frame in self.create_audio_frames(
layout="mono", sample_rate=8000, count=10
Expand All @@ -40,7 +40,7 @@ def test_encoder_mono_8hz(self):

def test_encoder_stereo_8khz(self):
encoder = get_encoder(PCMA_CODEC)
self.assertTrue(isinstance(encoder, PcmaEncoder))
self.assertIsInstance(encoder, PcmaEncoder)

for frame in self.create_audio_frames(
layout="stereo", sample_rate=8000, count=10
Expand All @@ -51,7 +51,7 @@ def test_encoder_stereo_8khz(self):

def test_encoder_stereo_48khz(self):
encoder = get_encoder(PCMA_CODEC)
self.assertTrue(isinstance(encoder, PcmaEncoder))
self.assertIsInstance(encoder, PcmaEncoder)

for frame in self.create_audio_frames(
layout="stereo", sample_rate=48000, count=10
Expand All @@ -72,7 +72,7 @@ def test_roundtrip_with_loss(self):
class PcmuTest(CodecTestCase):
def test_decoder(self):
decoder = get_decoder(PCMU_CODEC)
self.assertTrue(isinstance(decoder, PcmuDecoder))
self.assertIsInstance(decoder, PcmuDecoder)

frames = decoder.decode(JitterFrame(data=b"\xff" * 160, timestamp=0))
self.assertEqual(len(frames), 1)
Expand All @@ -87,7 +87,7 @@ def test_decoder(self):

def test_encoder_mono_8hz(self):
encoder = get_encoder(PCMU_CODEC)
self.assertTrue(isinstance(encoder, PcmuEncoder))
self.assertIsInstance(encoder, PcmuEncoder)

for frame in self.create_audio_frames(
layout="mono", sample_rate=8000, count=10
Expand All @@ -98,7 +98,7 @@ def test_encoder_mono_8hz(self):

def test_encoder_stereo_8khz(self):
encoder = get_encoder(PCMU_CODEC)
self.assertTrue(isinstance(encoder, PcmuEncoder))
self.assertIsInstance(encoder, PcmuEncoder)

for frame in self.create_audio_frames(
layout="stereo", sample_rate=8000, count=10
Expand All @@ -109,7 +109,7 @@ def test_encoder_stereo_8khz(self):

def test_encoder_stereo_48khz(self):
encoder = get_encoder(PCMU_CODEC)
self.assertTrue(isinstance(encoder, PcmuEncoder))
self.assertIsInstance(encoder, PcmuEncoder)

for frame in self.create_audio_frames(
layout="stereo", sample_rate=48000, count=10
Expand Down
8 changes: 4 additions & 4 deletions tests/test_h264.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_parse_nalu(self):
class H264Test(CodecTestCase):
def test_decoder(self):
decoder = get_decoder(H264_CODEC)
self.assertTrue(isinstance(decoder, H264Decoder))
self.assertIsInstance(decoder, H264Decoder)

# decode junk
with redirect_stderr(io.StringIO()):
Expand All @@ -115,7 +115,7 @@ def test_decoder(self):

def test_encoder(self):
encoder = get_encoder(H264_CODEC)
self.assertTrue(isinstance(encoder, H264Encoder))
self.assertIsInstance(encoder, H264Encoder)

frame = self.create_video_frame(width=640, height=480, pts=0)
packages, timestamp = encoder.encode(frame)
Expand All @@ -131,7 +131,7 @@ def mock_create_encoder_context(*args, **kwargs):
h264.create_encoder_context = mock_create_encoder_context
try:
encoder = get_encoder(H264_CODEC)
self.assertTrue(isinstance(encoder, H264Encoder))
self.assertIsInstance(encoder, H264Encoder)

frame = self.create_video_frame(width=640, height=480, pts=0)
packages, timestamp = encoder.encode(frame)
Expand All @@ -145,7 +145,7 @@ def mock_create_encoder_context(*args, **kwargs):

def test_encoder_target_bitrate(self):
encoder = get_encoder(H264_CODEC)
self.assertTrue(isinstance(encoder, H264Encoder))
self.assertIsInstance(encoder, H264Encoder)
self.assertEqual(encoder.target_bitrate, 1000000)

frame = self.create_video_frame(width=640, height=480, pts=0)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class OpusTest(CodecTestCase):
def test_decoder(self):
decoder = get_decoder(OPUS_CODEC)
self.assertTrue(isinstance(decoder, OpusDecoder))
self.assertIsInstance(decoder, OpusDecoder)

frames = decoder.decode(JitterFrame(data=b"\xfc\xff\xfe", timestamp=0))
self.assertEqual(len(frames), 1)
Expand All @@ -29,7 +29,7 @@ def test_decoder(self):

def test_encoder_mono_8khz(self):
encoder = get_encoder(OPUS_CODEC)
self.assertTrue(isinstance(encoder, OpusEncoder))
self.assertIsInstance(encoder, OpusEncoder)

frames = self.create_audio_frames(layout="mono", sample_rate=8000, count=2)

Expand All @@ -44,7 +44,7 @@ def test_encoder_mono_8khz(self):

def test_encoder_stereo_8khz(self):
encoder = get_encoder(OPUS_CODEC)
self.assertTrue(isinstance(encoder, OpusEncoder))
self.assertIsInstance(encoder, OpusEncoder)

frames = self.create_audio_frames(layout="stereo", sample_rate=8000, count=2)

Expand All @@ -59,7 +59,7 @@ def test_encoder_stereo_8khz(self):

def test_encoder_stereo_48khz(self):
encoder = get_encoder(OPUS_CODEC)
self.assertTrue(isinstance(encoder, OpusEncoder))
self.assertIsInstance(encoder, OpusEncoder)

frames = self.create_audio_frames(layout="stereo", sample_rate=48000, count=2)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_rtcdtlstransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_generate(self):

expires = certificate.expires
self.assertIsNotNone(expires)
self.assertTrue(isinstance(expires, datetime.datetime))
self.assertIsInstance(expires, datetime.datetime)

fingerprints = certificate.getFingerprints()
self.assertEqual(len(fingerprints), 1)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_rtcpeerconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ async def _test_connect_audio_bidirectional(self, pc1, pc2):

# check stats
report = await pc1.getStats()
self.assertTrue(isinstance(report, RTCStatsReport))
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
[
Expand Down Expand Up @@ -1235,7 +1235,7 @@ async def test_connect_audio_codec_preferences_offerer(self):

# check stats
report = await pc1.getStats()
self.assertTrue(isinstance(report, RTCStatsReport))
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
[
Expand Down Expand Up @@ -2675,7 +2675,7 @@ async def test_connect_video_bidirectional(self):

# check stats
report = await pc1.getStats()
self.assertTrue(isinstance(report, RTCStatsReport))
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
[
Expand Down
8 changes: 4 additions & 4 deletions tests/test_rtcrtpreceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class RTCRtpReceiverTest(CodecTestCase):
def test_capabilities(self):
# audio
capabilities = RTCRtpReceiver.getCapabilities("audio")
self.assertTrue(isinstance(capabilities, RTCRtpCapabilities))
self.assertIsInstance(capabilities, RTCRtpCapabilities)
self.assertEqual(
capabilities.codecs,
[
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_capabilities(self):

# video
capabilities = RTCRtpReceiver.getCapabilities("video")
self.assertTrue(isinstance(capabilities, RTCRtpCapabilities))
self.assertIsInstance(capabilities, RTCRtpCapabilities)
self.assertEqual(
capabilities.codecs,
[
Expand Down Expand Up @@ -348,7 +348,7 @@ async def test_rtp_and_rtcp(self):

# check stats
report = await receiver.getStats()
self.assertTrue(isinstance(report, RTCStatsReport))
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
["inbound-rtp", "remote-outbound-rtp", "transport"],
Expand All @@ -357,7 +357,7 @@ async def test_rtp_and_rtcp(self):
# check sources
sources = receiver.getSynchronizationSources()
self.assertEqual(len(sources), 1)
self.assertTrue(isinstance(sources[0], RTCRtpSynchronizationSource))
self.assertIsInstance(sources[0], RTCRtpSynchronizationSource)
self.assertEqual(sources[0].source, 4028317929)

# check remote track
Expand Down
6 changes: 3 additions & 3 deletions tests/test_rtcrtpsender.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RTCRtpSenderTest(TestCase):
def test_capabilities(self):
# audio
capabilities = RTCRtpSender.getCapabilities("audio")
self.assertTrue(isinstance(capabilities, RTCRtpCapabilities))
self.assertIsInstance(capabilities, RTCRtpCapabilities)
self.assertEqual(
capabilities.codecs,
[
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_capabilities(self):

# video
capabilities = RTCRtpSender.getCapabilities("video")
self.assertTrue(isinstance(capabilities, RTCRtpCapabilities))
self.assertIsInstance(capabilities, RTCRtpCapabilities)
self.assertEqual(
capabilities.codecs,
[
Expand Down Expand Up @@ -231,7 +231,7 @@ async def test_handle_rtcp_rr(self):

# check stats
report = await sender.getStats()
self.assertTrue(isinstance(report, RTCStatsReport))
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
["outbound-rtp", "remote-inbound-rtp", "transport"],
Expand Down
Loading

0 comments on commit 6a0654d

Please sign in to comment.