Skip to content

Commit

Permalink
test: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpaudel93 committed Oct 16, 2023
1 parent de4c1c0 commit e84ed29
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions tests/test_m3uparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
package_root_directory = file.parents[1]
sys.path.append(str(package_root_directory))

from m3u_parser import FilterConfig, M3uParser, ParseConfig, SortConfig
from m3u_parser import M3uParser, ParseConfig, SortConfig
from m3u_parser.exceptions import NoStreamsException

# Sample M3U content for testing
SAMPLE_M3U_CONTENT = """
Expand Down Expand Up @@ -66,6 +67,22 @@ def test_filter_by_status(self, temp_m3u_file):
streams = parser.get_list()
assert len(streams) == 3

# Test filtering by invalid category
def test_filter_by_invalid_category(self, temp_m3u_file):
parser = M3uParser()
parser.parse_m3u(temp_m3u_file, ParseConfig(check_live=False))
parser.filter_by('category', 'Invalid')
streams = parser.get_list()
assert len(streams) == 0

# Test filtering by invalid category
def test_filter_by_invalid_key(self, temp_m3u_file):
parser = M3uParser()
parser.parse_m3u(temp_m3u_file, ParseConfig(check_live=False))
parser.filter_by('invalid', 'Invalid')
streams = parser.get_list()
assert len(streams) == 0

# Test sorting by stream name in ascending order
def test_sort_by_name_asc(self, temp_m3u_file):
parser = M3uParser()
Expand Down Expand Up @@ -128,10 +145,11 @@ def test_retrieve_by_category(self, temp_m3u_file):
assert len(streams) == 3

# Test parsing invalid M3U content
# def test_invalid_m3u_content(self, tmpdir):
# invalid_m3u_file = tmpdir.join("invalid.m3u")
# with open(invalid_m3u_file, "w") as f:
# f.write("Invalid M3U Content")
# parser = M3uParser()
# with pytest.raises(Exception):
# parser.parse_m3u(str(invalid_m3u_file))
def test_invalid_m3u_content(self, tmpdir):
invalid_m3u_file = tmpdir.join("invalid.m3u")
with open(invalid_m3u_file, "w") as f:
f.write("Invalid M3U Content")
parser = M3uParser()
with pytest.raises(NoStreamsException):
parser.parse_m3u(str(invalid_m3u_file))
parser.get_random_stream()

0 comments on commit e84ed29

Please sign in to comment.