Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Added tests.

One is to test `convert_rate` and `reverse_converse_rate` in `download_manager.py`.
  • Loading branch information
Solomon1732 committed Sep 12, 2023
1 parent 109ff56 commit 786be85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ def convert_rate(rate: int) -> int:
"""
if rate == 0:
return -1
elif rate == -1:
if rate == -1:
return 1
else:
return rate * 1024
return rate * 1024

@staticmethod
def reverse_convert_rate(rate: int) -> int:
Expand All @@ -153,10 +152,9 @@ def reverse_convert_rate(rate: int) -> int:
"""
if rate == -1:
return 0
elif rate == 1:
if rate == 1:
return -1
else:
return rate // 1024
return rate // 1024

async def _check_dht_ready(self, min_dht_peers=60):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ async def test_start_download_existing_handle(fake_dlmgr):
await download.shutdown()


def test_convert_rate():
assert DownloadManager.convert_rate(0) == -1 # 0 is a special value
assert DownloadManager.convert_rate(-1) == 1 # -1 is a special value
for test_num in [1, 2, -2]:
assert DownloadManager.convert_rate(test_num) == test_num * 1024


def test_reverse_convert_rate():
assert DownloadManager.reverse_convert_rate(-1) == 0 # -1 is a special value
assert DownloadManager.reverse_convert_rate(1) == -1 # 1 is a special value
for test_num in [0, 2, -2]:
assert DownloadManager.reverse_convert_rate(test_num) == test_num // 1024


def test_start_download_existing_download(fake_dlmgr):
"""
Testing the addition of a torrent to the libtorrent manager, if there is a pre-existing download.
Expand Down

0 comments on commit 786be85

Please sign in to comment.