Skip to content

Commit

Permalink
SCC: Add unit tests for SccWord.get_channel
Browse files Browse the repository at this point in the history
Check that it produces the correct result for some known codes, and that
none of the methods crash for all possible codes.
  • Loading branch information
atsampson committed May 14, 2024
1 parent 48747c3 commit 6d22294
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/python/test_scc_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import unittest

from ttconv.scc.codes import SccChannel
from ttconv.scc.codes.control_codes import SccControlCode
from ttconv.scc.codes.extended_characters import SccExtendedCharacter
from ttconv.scc.codes.mid_row_codes import SccMidRowCode
Expand Down Expand Up @@ -136,3 +137,26 @@ def test_scc_word_get_code(self):
self.assertEqual(None, SccWord.from_str("2065").get_code()) # " e"
self.assertEqual(None, SccWord.from_str("6c69").get_code()) # "li"
self.assertEqual(None, SccWord.from_str("742e").get_code()) # "t."

def test_scc_word_get_channel(self):
# invalid codes
self.assertEqual(None, SccWord.from_value(0x1000).get_channel())
self.assertEqual(None, SccWord.from_value(0x1432).get_channel())
self.assertEqual(None, SccWord.from_value(0x1d00).get_channel())
self.assertEqual(None, SccWord.from_value(0x1f38).get_channel())

# Preamble Address Code
self.assertEqual(SccChannel.CHANNEL_1, SccWord.from_value(0x91d0).get_channel())
self.assertEqual(SccChannel.CHANNEL_2, SccWord.from_value(0x99d0).get_channel())

# Attribute Code
self.assertEqual(SccChannel.CHANNEL_1, SccWord.from_value(0x1020).get_channel())
self.assertEqual(SccChannel.CHANNEL_2, SccWord.from_value(0x1820).get_channel())

def test_scc_word_all_values(self):
# check that all possible values decode to something
for i in range(0x10000):
scc_word = SccWord.from_value(i)
scc_word.to_text()
scc_word.get_code()
scc_word.get_channel()

0 comments on commit 6d22294

Please sign in to comment.