Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_color_parsing():
solid_color = Color(r=1, g=2, b=3)
transparent_color = Color(r=1, g=2, b=3, a=4)
assert ssa_rgb_to_color(color_to_ssa_rgb(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(transparent_color)) == transparent_color
assert ass_rgba_to_color("&HAABBCCDD") == Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)
assert color_to_ass_rgba(Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)) == "&HAABBCCDD"
def build(self, **extra):
from pysubs2 import SSAFile, SSAEvent, Color # type: ignore[import]
millis = lambda td: td / timedelta(milliseconds=1)
subs = (
SSAEvent(
start=millis(t - self.start),
end =millis(t - self.start + timedelta(seconds=length)),
text=text.replace('\n', r'\N'), # \N necessary for SSA files
) for t, text, length in self.l
)
sf = SSAFile()
style = sf.styles['Default'].copy()
style.fontsize = 16 # default is 20, bit too much??
style.outlinecolor = Color(0, 0, 0, 50) # semitransparent
style.shadow = 0.0
style.outline = 0.1
style.borderstyle = 3 # no idea why 3, but it makes the background apperar in conjunction with outline
for k, v in extra.items():
setattr(style, k, v)
sf.styles['Default'] = style
for s in subs:
sf.append(s)
return sf.to_string('ass')
def test_color_parsing():
solid_color = Color(r=1, g=2, b=3)
transparent_color = Color(r=1, g=2, b=3, a=4)
assert ssa_rgb_to_color(color_to_ssa_rgb(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(transparent_color)) == transparent_color
assert ass_rgba_to_color("&HAABBCCDD") == Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)
assert color_to_ass_rgba(Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)) == "&HAABBCCDD"
def test_color_parsing():
solid_color = Color(r=1, g=2, b=3)
transparent_color = Color(r=1, g=2, b=3, a=4)
assert ssa_rgb_to_color(color_to_ssa_rgb(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(transparent_color)) == transparent_color
assert ass_rgba_to_color("&HAABBCCDD") == Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)
assert color_to_ass_rgba(Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)) == "&HAABBCCDD"
def test_color_parsing():
solid_color = Color(r=1, g=2, b=3)
transparent_color = Color(r=1, g=2, b=3, a=4)
assert ssa_rgb_to_color(color_to_ssa_rgb(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(solid_color)) == solid_color
assert ass_rgba_to_color(color_to_ass_rgba(transparent_color)) == transparent_color
assert ass_rgba_to_color("&HAABBCCDD") == Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)
assert color_to_ass_rgba(Color(r=0xDD, g=0xCC, b=0xBB, a=0xAA)) == "&HAABBCCDD"