1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_m3u.py
Kelly Brazil c8720b259c optimize tests
2022-09-23 14:02:27 -07:00

47 lines
1.4 KiB
Python

import os
import unittest
import json
import jc.parsers.m3u
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/m3u-example.m3u'), 'r', encoding='utf-8') as f:
m3u_example = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/m3u-dirty.m3u'), 'r', encoding='utf-8') as f:
m3u_dirty = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/m3u-example.json'), 'r', encoding='utf-8') as f:
m3u_example_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/m3u-dirty.json'), 'r', encoding='utf-8') as f:
m3u_dirty_json = json.loads(f.read())
def test_m3u_nodata(self):
"""
Test 'm3u' parser with no data
"""
self.assertEqual(jc.parsers.m3u.parse('', quiet=True), [])
def test_m3u_example(self):
"""
Test 'm3u' example file
"""
self.assertEqual(jc.parsers.m3u.parse(self.m3u_example, quiet=True), self.m3u_example_json)
def test_m3u_dirty(self):
"""
Test 'm3u' example file with lots of difficult parsing
"""
self.assertEqual(jc.parsers.m3u.parse(self.m3u_dirty, quiet=True), self.m3u_dirty_json)
if __name__ == '__main__':
unittest.main()