defl/tests/test_tree.py
2024-09-11 11:14:03 -04:00

184 lines
5.0 KiB
Python
Executable File

#!/usr/bin/env python
import argparse
import json
import defl
from defl import cl
parser = argparse.ArgumentParser(description='')
parser.add_argument('-z', '--log', default='info')
ag = parser.parse_args()
log = defl.log.setLevel(ag.log)
###########################################
toTree = {
"format": {
"bit_rate": "137650",
"duration": "10.010000",
"filename": "./downConvert_S01E05.avi_spd-fast_crf-28_sh-480-qsc-9.mp4[section_90-100].mp4",
"format_long_name": "QuickTime / MOV",
"format_name": "mov,mp4,m4a,3gp,3g2,mj2",
"nb_programs": 0,
"nb_streams": 2,
"probe_score": 100,
"size": "172235",
"start_time": "0.000000",
"tags": {
"compatible_brands": "isomiso2avc1mp41",
"encoder": "Lavf58.76.100",
"major_brand": "isom",
"minor_version": "512"
}
},
"streams": [
{
"avg_frame_rate": "24000/1001",
"bit_rate": "59576",
"bits_per_raw_sample": "8",
"chroma_location": "left",
"closed_captions": 0,
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"codec_name": "h264",
"codec_tag": "0x31637661",
"codec_tag_string": "avc1",
"codec_type": "video",
"coded_height": 134,
"coded_width": 240,
"display_aspect_ratio": "9:5",
"disposition": {
"attached_pic": 0,
"clean_effects": 0,
"comment": 0,
"default": 1,
"dub": 0,
"forced": 0,
"hearing_impaired": 0,
"karaoke": 0,
"lyrics": 0,
"original": 0,
"timed_thumbnails": 0,
"visual_impaired": 0
},
"duration": "10.010000",
"duration_ts": 240240,
"has_b_frames": 2,
"height": 134,
"index": 0,
"is_avc": "true",
"level": 12,
"nal_length_size": "4",
"nb_frames": "240",
"pix_fmt": "yuv420p",
"profile": "High",
"r_frame_rate": "24000/1001",
"refs": 1,
"sample_aspect_ratio": "201:200",
"start_pts": 0,
"start_time": "0.000000",
"tags": {
"handler_name": "VideoHandler",
"language": "und",
"vendor_id": "[0][0][0][0]"
},
"time_base": "1/24000",
"width": 240
},
{
"avg_frame_rate": "0/0",
"bit_rate": "70940",
"bits_per_sample": 0,
"channel_layout": "mono",
"channels": 1,
"codec_long_name": "AAC (Advanced Audio Coding)",
"codec_name": "aac",
"codec_tag": "0x6134706d",
"codec_tag_string": "mp4a",
"codec_type": "audio",
"disposition": {
"attached_pic": 0,
"clean_effects": 0,
"comment": 0,
"default": 1,
"dub": 0,
"forced": 0,
"hearing_impaired": 0,
"karaoke": 0,
"lyrics": 0,
"original": 0,
"timed_thumbnails": 0,
"visual_impaired": 0
},
"duration": "10.000000",
"duration_ts": 441000,
"index": 1,
"nb_frames": "432",
"profile": "LC",
"r_frame_rate": "0/0",
"sample_fmt": "fltp",
"sample_rate": "44100",
"start_pts": 0,
"start_time": "0.000000",
"tags": {
"handler_name": "SoundHandler",
"language": "und",
"vendor_id": "[0][0][0][0]"
},
"time_base": "1/44100"
}
]
}
tree = defl.Tree(toTree)
print(defl.jdumps(tree, indent=2, sort_keys=True))
assert defl.jdumps(tree, indent=2, sort_keys=True) == defl.jdumps(toTree, indent=2, sort_keys=True)
t = defl.Tree()
# t[[1]] = "4"
# t[[1, 1]] = "4"
t[[1, 1, 1]] = "4"
# t[2] = "5"
# t[2, 2] = "5"
t[2, 2, 2] = "5"
# t[3][3][3] = "6"
t[10, 11, 12, 13] = "21"
t[10, 11, 12, 14] = "22"
t[10, 11, 12, 14] = "22"
print(defl.jdumps(t, indent=2, sort_keys=True))
# assert defl.jdumps(t, indent=2, sort_keys=True) == defl.jdumps({
# "1": {
# "1": {
# "1": "4"
# }
# },
# "2": {
# "2": {
# "2": "5"
# }
# },
# "10": {
# "11": {
# "12": {
# "13": "21",
# "14": "22"
# }
# }
# }
# }, indent=2, sort_keys=True)
print('===========================================')
for i in t.keyGen():
print(i)
print('===========================================')
for i in t.itemGen():
print(i)
print('===========================================')
# t.inc(1, 1, 1, 1, 1, 1)
obj = [-1] * 5
for i in range(5):
t.inc(*obj)
print(t[obj])
assert t[obj] == 5
print(defl.jdumps(t, indent=2, sort_keys=True))