Skip to content

Commit

Permalink
SCC: Handle unrecognized SCC codes in SccWord.get_channel()
Browse files Browse the repository at this point in the history
  • Loading branch information
atsampson committed May 14, 2024
1 parent 536f1c8 commit c0f6929
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/python/ttconv/scc/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def is_code(self) -> bool:

def get_channel(self) -> Optional[SccChannel]:
"""Returns the caption channel, if the word is an SCC code"""
if self.is_code():
if isinstance(self.code, SccPreambleAddressCode):
return self.code.get_channel()
return self.code.get_channel(self.value)
return None
if self.code is None:
return None
if isinstance(self.code, SccPreambleAddressCode):
return self.code.get_channel()
return self.code.get_channel(self.value)
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 c0f6929

Please sign in to comment.