Skip to content

Commit

Permalink
fix core tests and reorganize tests folder
Browse files Browse the repository at this point in the history
fix core tests

xfail test that should be invalid

test correct default providers

failing tests

skip creating rar archives if rar is not installed

use gestdown instead of addic7ed

remove python2 stuff

reorganize tests folder
  • Loading branch information
getzze committed May 14, 2024
1 parent dda8f29 commit 7eb9811
Show file tree
Hide file tree
Showing 27 changed files with 1,883 additions and 4,936 deletions.
2 changes: 2 additions & 0 deletions subliminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def list_subtitles_provider(self, provider, video, languages):
except Exception as e:
handle_exception(e, 'Provider {}'.format(provider))

return []

def list_subtitles(self, video, languages):
"""List subtitles.
Expand Down
12 changes: 9 additions & 3 deletions subliminal/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def __init__(self, language, hearing_impaired=False, page_link=None, encoding=No
@property
def id(self):
"""Unique identifier of the subtitle"""
raise NotImplementedError
return ""

@property
def info(self):
"""Info of the subtitle, human readable. Usually the subtitle name for GUI rendering"""
raise NotImplementedError
return ""

@property
def text(self):
Expand Down Expand Up @@ -94,12 +94,18 @@ def is_valid(self):
return False

try:
srt.parse(self.text)
self.parsed()
except srt.SRTParseError:
return False

return True

def parsed(self):
"""Text content parsed to a valid subtitle.
"""
return srt.compose(srt.parse(self.text))

def guess_encoding(self):
"""Guess encoding using the language, falling back on chardet.
Expand Down
6 changes: 3 additions & 3 deletions subliminal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import socket
import struct
from datetime import datetime
from datetime import datetime, timezone

import requests
from requests.exceptions import SSLError
Expand Down Expand Up @@ -154,14 +154,14 @@ def sanitize_release_group(string):


def timestamp(date):
"""Get the timestamp of the `date`, python2/3 compatible
"""Get the timestamp of the `date` (with timezone).
:param datetime.datetime date: the utc date.
:return: the timestamp of the date.
:rtype: float
"""
return (date - datetime(1970, 1, 1)).total_seconds()
return (date - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()


def matches_title(actual, title, alternative_titles):
Expand Down
Loading

0 comments on commit 7eb9811

Please sign in to comment.