def test_errored_states(state): assert TorrentStates(state).is_errored
def test_paused_states(state): assert TorrentStates(state).is_paused
def test_completing_states(state): assert TorrentStates(state).is_complete
def test_checking_states(state): assert TorrentStates(state).is_checking
def test_uploading_states(state): assert TorrentStates(state).is_uploading
def test_downloading_states(state): assert TorrentStates(state).is_downloading
def test_all_states(state): assert TorrentStates(state) in TorrentStates
def test_torrent_states_exists(): assert isinstance(TorrentStates("unknown"), Enum)
def get_qbittorrent_torrent_tags_metrics(self): try: categories = self.client.torrent_categories.categories except Exception as e: logger.error(f"Couldn't fetch categories: {e}") return [] if not self.torrents: return [] metrics = [] categories.Uncategorized = AttrDict({'name': 'Uncategorized', 'savePath': ''}) for category in categories: category_torrents = [t for t in self.torrents if t['category'] == category or (category == "Uncategorized" and t['category'] == "")] for status in self.TORRENT_STATUSES: status_prop = f"is_{status}" status_torrents = [ t for t in category_torrents if getattr(TorrentStates, status_prop).fget(TorrentStates(t['state'])) ] metrics.append({ "name": f"{self.config['metrics_prefix']}_torrents_count", "value": len(status_torrents), "labels": { "status": status, "category": category, }, "help": f"Number of torrents in status {status} under category {category}" }) return metrics