Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb90212

Browse files
palemieuxvalnoelBobBrownConsulting
authoredNov 19, 2020
Add unit test coverage to CI script (sandflow#131)
Closes sandflow#64 * Add unit test coverage to CI script (sandflow#64) * Code coverage greater than 80% across all files (sandflow#64) Co-authored-by: Valentin NOEL <valentin.noel@media-io.com> Co-authored-by: Bob Brown <bob@bigleafdesigns.com>
1 parent 30f123f commit bb90212

File tree

8 files changed

+86
-18
lines changed

8 files changed

+86
-18
lines changed
 

‎.coveragerc

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[run]
22
data_file = build/.coverage
3+
source_pkgs = ttconv
34

45
[html]
56
directory = build/htmlcov

‎scripts/ci.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pipenv run python -m pylint src/main/python/ttconv/ src/test/python/
66

7-
## Unit tests
8-
9-
pipenv run python -m unittest discover -v -s src/test/python/ -t .
7+
## unit test and coverage
108

9+
pipenv run coverage run -m unittest discover -v -s src/test/python/ -t .
10+
pipenv run coverage report | awk '!/-|(Name)/ {if (int($NF) < 80) {print $1 " has less than 80% coverage"; flag=2;}}; END { if (flag) exit(flag)}'

‎scripts/coverage.sh

100644100755
File mode changed.

‎src/main/python/ttconv/imsc/style_properties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def local_name(cls):
5555
raise NotImplementedError
5656

5757
@classmethod
58-
def has_px(cls, attrib_value: typing.Any) -> bool:
58+
def has_px(cls, _attrib_value: typing.Any) -> bool:
5959
return False
6060

6161
@classmethod

‎src/main/python/ttconv/imsc/writer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
'''IMSC writer'''
2727

2828
import logging
29+
import xml.etree.ElementTree as et
2930
import ttconv.imsc.elements as imsc_elements
3031
import ttconv.imsc.namespaces as xml_ns
3132
import ttconv.model as model
32-
import xml.etree.ElementTree as et
3333

3434
LOGGER = logging.getLogger(__name__)
3535

‎src/main/python/ttconv/scc/disassembly.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

2626
"""SCC disassembly functions"""
27+
import logging
2728

2829
from ttconv.style_properties import ColorType, NamedColors, FontStyleType, TextDecorationType
2930

31+
LOGGER = logging.getLogger(__name__)
3032

3133
def get_color_disassembly(color: ColorType) -> str:
3234
"""Get color disassembly code"""
@@ -35,28 +37,34 @@ def get_color_disassembly(color: ColorType) -> str:
3537
if color is None:
3638
return disassembly
3739

38-
if color is NamedColors.white.value:
40+
rgb_color = color.components[:-1]
41+
if rgb_color == NamedColors.white.value.components[:-1]:
3942
disassembly = "Wh"
40-
elif color is NamedColors.green.value:
43+
elif rgb_color == NamedColors.green.value.components[:-1]:
4144
disassembly = "Gr"
42-
elif color is NamedColors.blue.value:
45+
elif rgb_color == NamedColors.blue.value.components[:-1]:
4346
disassembly = "Bl"
44-
elif color is NamedColors.cyan.value:
47+
elif rgb_color == NamedColors.cyan.value.components[:-1]:
4548
disassembly = "Cy"
46-
elif color is NamedColors.red.value:
49+
elif rgb_color == NamedColors.red.value.components[:-1]:
4750
disassembly = "R"
48-
elif color is NamedColors.yellow.value:
51+
elif rgb_color == NamedColors.yellow.value.components[:-1]:
4952
disassembly = "Y"
50-
elif color is NamedColors.magenta.value:
53+
elif rgb_color == NamedColors.magenta.value.components[:-1]:
5154
disassembly = "Ma"
52-
elif color is NamedColors.black.value:
55+
elif rgb_color == NamedColors.black.value.components[:-1]:
5356
disassembly = "Bk"
54-
elif color is NamedColors.transparent.value:
55-
disassembly = "T"
5657

5758
# Alpha channel
58-
if color.components[3] == 0x88:
59+
if color.components[3] == 0:
60+
disassembly = "T"
61+
elif color.components[3] == 0x88:
5962
disassembly += "S"
63+
elif color.components[3] != 0xFF:
64+
LOGGER.warning("Skip unsupported %s alpha level in disassembly format.", color.components[3])
65+
66+
if not disassembly:
67+
LOGGER.warning("Unsupported '%s' color in disassembly format.", color.components)
6068

6169
return disassembly
6270

‎src/test/python/test_imsc_reader.py

+18
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,27 @@
3535
import ttconv.model as model
3636
import ttconv.style_properties as styles
3737
import ttconv.imsc.reader as imsc_reader
38+
import ttconv.imsc.namespaces as xml_ns
3839

3940
class IMSCReaderTest(unittest.TestCase):
4041

42+
def test_reader_tt_element_not_root_element(self):
43+
44+
xml_str = """<?xml version="1.0" encoding="UTF-8"?>
45+
<not_tt xml:lang="en"
46+
xmlns="http://www.w3.org/ns/ttml"
47+
xmlns:ttm="http://www.w3.org/ns/ttml#metadata"
48+
xmlns:tts="http://www.w3.org/ns/ttml#styling"
49+
xmlns:ttp="http://www.w3.org/ns/ttml#parameter"
50+
xmlns:ittp="http://www.w3.org/ns/ttml/profile/imsc1#parameter"
51+
ittp:activeArea="50% 50% 80% 80%"
52+
tts:extent="640px 480px"
53+
ttp:profile="http://www.w3.org/ns/ttml/profile/imsc1/text">
54+
</not_tt>"""
55+
56+
tt_not_root = et.ElementTree(et.fromstring(xml_str))
57+
self.assertIsNone(imsc_reader.to_model(tt_not_root))
58+
4159
def test_body_only(self):
4260
tree = et.parse('src/test/resources/ttml/body_only.ttml')
4361
imsc_reader.to_model(tree)

‎src/test/python/test_scc_disassembly.py

+43-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,54 @@
2929

3030
import unittest
3131

32-
from ttconv.scc.disassembly import get_text_decoration_disassembly
32+
from ttconv.scc.disassembly import get_color_disassembly, get_font_style_disassembly, get_text_decoration_disassembly
3333
from ttconv.scc.reader import to_disassembly
34-
from ttconv.style_properties import TextDecorationType
34+
from ttconv.style_properties import NamedColors, ColorType, FontStyleType, TextDecorationType
3535

3636

3737
class SccReaderTest(unittest.TestCase):
3838

39+
def test_scc_disassembly_color(self):
40+
disassembly_colors = {
41+
NamedColors.white: "Wh",
42+
NamedColors.green: "Gr",
43+
NamedColors.blue: "Bl",
44+
NamedColors.cyan: "Cy",
45+
NamedColors.aqua: "Cy",
46+
NamedColors.red: "R",
47+
NamedColors.yellow: "Y",
48+
NamedColors.magenta: "Ma",
49+
NamedColors.fuchsia: "Ma",
50+
NamedColors.black: "Bk",
51+
NamedColors.transparent: "T",
52+
NamedColors.silver: "",
53+
NamedColors.gray: "",
54+
NamedColors.maroon: "",
55+
NamedColors.purple: "",
56+
NamedColors.lime: "",
57+
NamedColors.olive: "",
58+
NamedColors.navy: "",
59+
NamedColors.teal: ""
60+
}
61+
62+
for (color, code) in disassembly_colors.items():
63+
self.assertEqual(code, get_color_disassembly(color.value))
64+
65+
self.assertEqual("BlS", get_color_disassembly(ColorType((0, 0, 255, 136))))
66+
self.assertEqual("Bl", get_color_disassembly(ColorType((0, 0, 255, 128))))
67+
self.assertEqual("Bl", get_color_disassembly(ColorType((0, 0, 255, 145))))
68+
self.assertEqual("T", get_color_disassembly(ColorType((0, 0, 255, 0))))
69+
70+
def test_scc_disassembly_font_style(self):
71+
disassembly_font_style = {
72+
FontStyleType.normal: "",
73+
FontStyleType.oblique: "",
74+
FontStyleType.italic: "I",
75+
}
76+
77+
for (font_style, code) in disassembly_font_style.items():
78+
self.assertEqual(code, get_font_style_disassembly(font_style))
79+
3980
def test_scc_disassembly_text_decoration(self):
4081
disassembly_text_decoration = {
4182
TextDecorationType(underline=True): "U",

0 commit comments

Comments
 (0)
Please sign in to comment.