Browse Source

Update 'TestUpdateStats' test case

doc-issue-template
MrS0m30n3 7 years ago
parent
commit
4cc8f45376
1 changed files with 108 additions and 17 deletions
  1. 125
      tests/test_ditem.py

125
tests/test_ditem.py

@ -144,7 +144,9 @@ class TestUpdateStats(unittest.TestCase):
def test_update_stats(self):
path = os.path.join("/home", "user")
self.ditem.update_stats({"filename": "somefilename",
# 1st playlist item
self.ditem.update_stats({"filename": "somefilename.f1",
"extension": ".mp4",
"filesize": "9.45MiB",
"percent": "2.0%",
@ -156,7 +158,7 @@ class TestUpdateStats(unittest.TestCase):
"playlist_index": "1"})
self.assertEqual(self.ditem.path, path)
self.assertEqual(self.ditem.filenames, ["somefilename"])
self.assertEqual(self.ditem.filenames, ["somefilename.f1"])
self.assertEqual(self.ditem.extensions, [".mp4"])
# Do not update filesizes unless percentage is 100%
@ -165,7 +167,7 @@ class TestUpdateStats(unittest.TestCase):
self.assertEqual(
self.ditem.progress_stats,
{"filename": "somefilename",
{"filename": "somefilename.f1",
"extension": ".mp4",
"filesize": "9.45MiB",
"percent": "2.0%",
@ -186,9 +188,47 @@ class TestUpdateStats(unittest.TestCase):
self.assertEqual(self.ditem.filesizes, [9909043.20])
self.ditem.update_stats({"filename": "someotherfilename",
self.ditem.update_stats({"filename": "somefilename.f2",
"extension": ".m4a",
"filesize": "2.00MiB",
"filesize": "2.22MiB",
"percent": "33.0%",
"speed": "200.00KiB/s",
"eta": "00:20",
"status": "Downloading",
"path": path})
self.assertEqual(self.ditem.path, path)
self.assertEqual(self.ditem.filenames, ["somefilename.f1", "somefilename.f2"])
self.assertEqual(self.ditem.extensions, [".mp4", ".m4a"])
self.assertEqual(self.ditem.filesizes, [9909043.20])
self.assertEqual(
self.ditem.progress_stats,
{"filename": "somefilename.f2",
"extension": ".m4a",
"filesize": "2.22MiB",
"percent": "33.0%",
"speed": "200.00KiB/s",
"eta": "00:20",
"status": "Downloading",
"playlist_size": "10",
"playlist_index": "1"}
)
# Since the percentage is 100% this should update the filesizes list
self.ditem.update_stats({"filesize": "2.22MiB",
"percent": "100%",
"speed": "",
"eta": "",
"status": "Downloading"})
self.assertEqual(self.ditem.filesizes, [9909043.20, 2327838.72])
# Moving to the 2nd playlist item
self.ditem.update_stats({"filename": "someotherfilename.f1",
"extension": ".mp4",
"filesize": "10.25MiB",
"percent": "50.0%",
"speed": "200.00KiB/s",
"eta": "00:38",
@ -197,14 +237,17 @@ class TestUpdateStats(unittest.TestCase):
"playlist_size": "10",
"playlist_index": "2"})
self.assertEqual(self.ditem.filenames, ["somefilename", "someotherfilename"])
self.assertEqual(self.ditem.extensions, [".mp4", ".m4a"])
self.assertEqual(self.ditem.filesizes, [9909043.20])
# We must reset filenames, extensions & filesizes lists when changing playlist index
# else the filesizes for the post processed files will be wrong
self.assertEqual(self.ditem.filenames, ["someotherfilename.f1"])
self.assertEqual(self.ditem.extensions, [".mp4"])
self.assertEqual(self.ditem.filesizes, [])
self.assertEqual(
self.ditem.progress_stats,
{"filename": "someotherfilename",
"extension": ".m4a",
"filesize": "2.00MiB",
{"filename": "someotherfilename.f1",
"extension": ".mp4",
"filesize": "10.25MiB",
"percent": "50.0%",
"speed": "200.00KiB/s",
"eta": "00:38",
@ -214,26 +257,74 @@ class TestUpdateStats(unittest.TestCase):
)
# Since the percentage is 100% this should update the filesizes list
self.ditem.update_stats({"filesize": "2.00MiB",
self.ditem.update_stats({"filesize": "10.25MiB",
"percent": "100%",
"speed": "",
"eta": "",
"status": "Downloading"})
self.assertEqual(self.ditem.filenames, ["somefilename", "someotherfilename"])
self.assertEqual(self.ditem.filesizes, [10747904.0])
self.ditem.update_stats({"filename": "someotherfilename.f2",
"extension": ".m4a",
"filesize": "3.33MiB",
"percent": "33.0%",
"speed": "200.00KiB/s",
"eta": "00:30",
"status": "Downloading",
"path": path})
self.assertEqual(self.ditem.path, path)
self.assertEqual(self.ditem.filenames, ["someotherfilename.f1", "someotherfilename.f2"])
self.assertEqual(self.ditem.extensions, [".mp4", ".m4a"])
self.assertEqual(self.ditem.filesizes, [9909043.20, 2097152.00])
self.assertEqual(self.ditem.filesizes, [10747904.0])
self.assertEqual(
self.ditem.progress_stats,
{"filename": "someotherfilename",
{"filename": "someotherfilename.f2",
"extension": ".m4a",
"filesize": "2.00MiB",
"filesize": "3.33MiB",
"percent": "33.0%",
"speed": "200.00KiB/s",
"eta": "00:30",
"status": "Downloading",
"playlist_size": "10",
"playlist_index": "2"}
)
# Since the percentage is 100% this should update the filesizes list
self.ditem.update_stats({"filesize": "3.33MiB",
"percent": "100%",
"speed": "",
"eta": "",
"status": "Downloading"})
self.assertEqual(self.ditem.filesizes, [10747904.0, 3491758.08])
# Let's move to the 3rd playlist item
# Here we mimic youtube-dl's "max downloads limit reached"
# this line should not reset the filenames, extensions & filesizes lists
# since we will lose the ability to play the last playlist item
self.ditem.update_stats({"status": "Downloading",
"playlist_size": "10",
"playlist_index": "3"})
self.assertEqual(self.ditem.filenames, ["someotherfilename.f1", "someotherfilename.f2"])
self.assertEqual(self.ditem.extensions, [".mp4", ".m4a"])
self.assertEqual(self.ditem.filesizes, [10747904.0, 3491758.08])
self.assertEqual(
self.ditem.progress_stats,
{"filename": "someotherfilename.f2",
"extension": ".m4a",
"filesize": "3.33MiB",
"percent": "100%",
"speed": "-",
"eta": "-",
"status": "Downloading",
"playlist_size": "10",
"playlist_index": "2"}
"playlist_index": "3"}
)
def test_update_stats_invalid_input(self):

Loading…
Cancel
Save