mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
Merge pull request #31 from olof/topic/timestr_fixes_unittest
Unittests for timestr
This commit is contained in:
commit
9d84a3b1f7
23
lib/svtplay_dl/tests/utils.py
Normal file
23
lib/svtplay_dl/tests/utils.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
# ex:ts=4:sw=4:sts=4:et
|
||||
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
# The unittest framwork doesn't play nice with pylint:
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
from __future__ import absolute_import
|
||||
import unittest
|
||||
import svtplay_dl.utils
|
||||
|
||||
class timestrTest(unittest.TestCase):
|
||||
def test_1(self):
|
||||
self.assertEqual(svtplay_dl.utils.timestr(1), "00:00:00,00")
|
||||
|
||||
def test_100(self):
|
||||
self.assertEqual(svtplay_dl.utils.timestr(100), "00:00:00,10")
|
||||
|
||||
def test_3600(self):
|
||||
self.assertEqual(svtplay_dl.utils.timestr(3600), "00:00:03,60")
|
||||
|
||||
def test_3600000(self):
|
||||
self.assertEqual(svtplay_dl.utils.timestr(3600000), "01:00:00,00")
|
@ -61,12 +61,25 @@ def get_http_data(url, method="GET", header="", data="", referer=None, cookiejar
|
||||
response.close()
|
||||
return data
|
||||
|
||||
def timestr(seconds):
|
||||
total = float(seconds) / 1000
|
||||
hours = int(total / 3600)
|
||||
minutes = int(total / 60)
|
||||
sec = total % 60
|
||||
output = "%02d:%02d:%02.02f" % (hours, minutes, sec)
|
||||
def timestr(msec):
|
||||
"""
|
||||
Convert a millisecond value to a string of the following
|
||||
format:
|
||||
|
||||
HH:MM:SS,SS
|
||||
|
||||
with 10 millisecond precision. Note the , seperator in
|
||||
the seconds.
|
||||
"""
|
||||
sec = float(msec) / 1000
|
||||
|
||||
hours = int(sec / 3600)
|
||||
sec -= hours * 3600
|
||||
|
||||
minutes = int(sec / 60)
|
||||
sec -= minutes * 60
|
||||
|
||||
output = "%02d:%02d:%05.2f" % (hours, minutes, sec)
|
||||
return output.replace(".", ",")
|
||||
|
||||
def norm(name):
|
||||
|
Loading…
Reference in New Issue
Block a user