def test_docstring_with_help(self): Documented = fixeddict( "Documented", Entry( "foo", help=""" Lots of help! """, ), Entry("bar", help="Some help", help_type="int"), help=""" A partially documented fixeddict. How nice? """, ) assert (Documented.__doc__ == dedent(""" A partially documented fixeddict. How nice? Parameters ========== foo Lots of help! bar : int Some help """).lstrip())
def test_help_type(self): v = Entry("v") assert v.help_type is None v = Entry( "v", help_type=""" foo bar """, ) assert v.help_type == "foo\nbar"
def test_help(self): v = Entry("v") assert v.help is None v = Entry( "v", help=""" foo bar """, ) assert v.help == "foo\nbar"
def test_docstring_no_help(self): Undocumented = fixeddict( "Undocumented", Entry("foo"), Entry("bar"), ) assert (Undocumented.__doc__ == dedent(""" A :py:mod:`~vc2_conformance.fixeddict`. Parameters ========== foo bar """).lstrip())
from vc2_conformance.pseudocode.slice_sizes import slices_have_same_dimensions from vc2_conformance.fixeddict import fixeddict, Entry __all__ = [ "CodecFeatures", "InvalidCodecFeaturesError", "read_codec_features_csv", "codec_features_to_trivial_level_constraints", ] CodecFeatures = fixeddict( "CodecFeatures", Entry("name"), # (11.2.1) Entry("level", enum=Levels), Entry("profile", enum=Profiles), # (11.1) Entry("picture_coding_mode", enum=PictureCodingModes), # (11.4) Entry("video_parameters"), # VideoParameters # (12.4.1) and (12.4.4.1) Entry("wavelet_index", enum=WaveletFilters), Entry("wavelet_index_ho", enum=WaveletFilters), Entry("dwt_depth"), Entry("dwt_depth_ho"), # (12.4.5.2) Entry("slices_x"), Entry("slices_y"),
.. warning:: For default values containing a :py:class:`bitarray.bitarray` or any other mutable type, users must take care to copy the default value before mutating it. """ ################################################################################ # parse_info header ################################################################################ ParseInfo = fixeddict( "ParseInfo", Entry( "padding", formatter=Bits(), help_type=":py:class:`~bitarray.bitarray`", help="Byte alignment padding bits.", ), Entry( "parse_info_prefix", friendly_formatter=(lambda prefix: "Correct" if prefix == PARSE_INFO_PREFIX else "INCORRECT"), formatter=Hex(8), help_type="int", ), Entry( "parse_code", enum=ParseCodes, formatter=Hex(2), help_type=":py:class:`~vc2_data_tables.ParseCodes`", ),
"set_coding_parameters", "picture_dimensions", "video_depth", "preset_frame_rate", "preset_pixel_aspect_ratio", "preset_signal_range", "preset_color_primaries", "preset_color_matrix", "preset_transfer_function", "preset_color_spec", ] VideoParameters = fixeddict( "VideoParameters", # (11.4.3) frame_size Entry("frame_width", help_type="int", help="Set by (11.4.3) frame_size"), Entry("frame_height", help_type="int", help="Set by (11.4.3) frame_size"), # (11.4.4) color_diff_sampling_format Entry( "color_diff_format_index", enum=ColorDifferenceSamplingFormats, help_type=":py:class:`~vc2_data_tables.ColorDifferenceSamplingFormats`", help="Set by (11.4.4) color_diff_sampling_format", ), # (11.4.5) scan_format Entry( "source_sampling", enum=SourceSamplingModes, help_type=":py:class:`~vc2_data_tables.SourceSamplingModes`", help="Set by (11.4.5) scan_format", ),
def test_to_string(self): v = Entry("v") assert v.to_string(123) == "123" assert v.to_string("abc") == "abc" v = Entry("v", formatter=bin) assert v.to_string(0b1010) == "0b1010" v = Entry("v", friendly_formatter=str.upper) assert v.to_string("foo") == "FOO (foo)" v = Entry("v", formatter=str.lower, friendly_formatter=str.upper) assert v.to_string("Foo") == "FOO (foo)"
def test_enum(self): class MyEnum(IntEnum): a = 1 b = 2 c = 3 v = Entry("v", enum=MyEnum) assert v.to_string(1) == "a (1)" assert v.to_string(2) == "b (2)" assert v.to_string(3) == "c (3)" assert v.to_string(MyEnum.a) == "a (1)" assert v.to_string(MyEnum.b) == "b (2)" assert v.to_string(MyEnum.c) == "c (3)" assert v.to_string(0) == "0" assert v.to_string("foo") == "foo" # Check can override formatter/friendly_formatter v = Entry("v", enum=MyEnum, formatter=hex) assert v.to_string(MyEnum.a) == "a (0x1)" assert v.to_string(MyEnum.b) == "b (0x2)" assert v.to_string(MyEnum.c) == "c (0x3)" v = Entry("v", enum=MyEnum, friendly_formatter=repr) assert v.to_string(MyEnum.a) == "<MyEnum.a: 1> (1)" assert v.to_string(MyEnum.b) == "<MyEnum.b: 2> (2)" assert v.to_string(MyEnum.c) == "<MyEnum.c: 3> (3)"
def test_with_friendly_formatter(self): v = Entry("v", friendly_formatter=hex) assert v.formatter is str assert v.friendly_formatter is hex
def test_no_args(self): v = Entry("v") assert v.name == "v" assert v.formatter is str assert v.friendly_formatter is None
assert v.help_type is None v = Entry( "v", help_type=""" foo bar """, ) assert v.help_type == "foo\nbar" MyFixedDict = fixeddict( "MyFixedDict", # No formatter Entry("name"), # With a formatter Entry("age", friendly_formatter=str, formatter=hex), # Hidden value Entry("_hidden"), ) class TestFixedDict(object): def test_constructors(self): # Sanity check standard dictionary initialisation works # Check empty initialiser d = MyFixedDict() assert d == {}
Levels, ) from vc2_conformance.fixeddict import fixeddict, Entry __all__ = [ "State", "reset_state", ] State = fixeddict( "State", # (10.4.1) parse_sequence Entry( "video_parameters", help_type=":py:class:`~vc2_conformance.pseudocode.video_parameters.VideoParameters`", help="Set by (10.4.1) parse_sequence", ), # (10.5.1) parse_info Entry( "parse_code", enum=ParseCodes, formatter=Hex(2), help_type=":py:class:`~vc2_data_tables.ParseCodes`", help="Set by (10.5.1) parse_info", ), Entry("next_parse_offset", help_type="int", help="Set by (10.5.1) parse_info"), Entry("previous_parse_offset", help_type="int", help="Set by (10.5.1) parse_info"), # (11.1) sequence_header Entry( "picture_coding_mode",