/ tests / test_stats.py
test_stats.py
  1  """Tests for the `stats` module."""
  2  
  3  from __future__ import annotations
  4  
  5  import pytest
  6  
  7  from aria2p import Stats
  8  
  9  
 10  @pytest.fixture(scope="module")
 11  def stats() -> Stats:
 12      """Provide a Stats instance.
 13  
 14      Returns:
 15          A Stats instance.
 16      """
 17      return Stats(
 18          {
 19              "downloadSpeed": "0",
 20              "numActive": "0",
 21              "numStopped": "0",
 22              "numStoppedTotal": "0",
 23              "numWaiting": "0",
 24              "uploadSpeed": "0",
 25          },
 26      )
 27  
 28  
 29  def test_download_speed(stats: Stats) -> None:
 30      """Test the `download_speed` property.
 31  
 32      Parameters:
 33          stats: A Stats instance.
 34      """
 35      assert stats.download_speed == 0
 36  
 37  
 38  def test_download_speed_string(stats: Stats) -> None:
 39      """Test the `download_speed_string` method.
 40  
 41      Parameters:
 42          stats: A Stats instance.
 43      """
 44      assert stats.download_speed_string() == "0.00 B/s"
 45  
 46  
 47  def test_download_speed_string_not_human_readable(stats: Stats) -> None:
 48      """Test the `download_speed_string` method with human readable option.
 49  
 50      Parameters:
 51          stats: A Stats instance.
 52      """
 53      assert stats.download_speed_string(human_readable=False) == "0 B/s"
 54  
 55  
 56  def test_upload_speed(stats: Stats) -> None:
 57      """Test the `upload_speed` property.
 58  
 59      Parameters:
 60          stats: A Stats instance.
 61      """
 62      assert stats.upload_speed == 0
 63  
 64  
 65  def test_upload_speed_string(stats: Stats) -> None:
 66      """Test the `upload_speed_string` method.
 67  
 68      Parameters:
 69          stats: A Stats instance.
 70      """
 71      assert stats.upload_speed_string() == "0.00 B/s"
 72  
 73  
 74  def test_upload_speed_string_not_human_readable(stats: Stats) -> None:
 75      """Test the `upload_speed_string` method with human readable option.
 76  
 77      Parameters:
 78          stats: A Stats instance.
 79      """
 80      assert stats.upload_speed_string(human_readable=False) == "0 B/s"
 81  
 82  
 83  def test_num_active(stats: Stats) -> None:
 84      """Test the `numnum_active_waiting` property.
 85  
 86      Parameters:
 87          stats: A Stats instance.
 88      """
 89      assert stats.num_active == 0
 90  
 91  
 92  def test_num_stopped(stats: Stats) -> None:
 93      """Test the `num_stopped` property.
 94  
 95      Parameters:
 96          stats: A Stats instance.
 97      """
 98      assert stats.num_stopped == 0
 99  
100  
101  def test_num_stopped_total(stats: Stats) -> None:
102      """Test the `num_stopped_total` property.
103  
104      Parameters:
105          stats: A Stats instance.
106      """
107      assert stats.num_stopped_total == 0
108  
109  
110  def test_num_waiting(stats: Stats) -> None:
111      """Test the `num_waiting` property.
112  
113      Parameters:
114          stats: A Stats instance.
115      """
116      assert stats.num_waiting == 0