From 0e08ffb4dc37fb4660daf2ba32ce95f8bf856df7 Mon Sep 17 00:00:00 2001 From: jerrymakesjelly Date: Thu, 13 Feb 2020 13:36:56 +0800 Subject: [PATCH] Add some conditions to condition parser CLoses #49, #62. --- autoremovetorrents/conditionparser.py | 14 +++++++++++++- .../test_average_downloadspeed_gt.yml | 4 ++++ .../test_average_downloadspeed_lt.yml | 5 +++++ .../test_average_uploadspeed_gt.yml | 5 +++++ .../test_average_uploadspeed_lt.yml | 5 +++++ .../test_connected_leecher_gt.yml | 4 ++++ .../test_connected_leecher_lt.yml | 7 +++++++ .../remove_conditions/test_connected_seeder_gt.yml | 5 +++++ .../remove_conditions/test_connected_seeder_lt.yml | 13 +++++++++++++ .../cases/remove_conditions/test_leecher_gt.yml | 4 ++++ .../cases/remove_conditions/test_leecher_lt.yml | 10 ++++++++++ .../cases/remove_conditions/test_seeder_gt.yml | 14 ++++++++++++++ .../cases/remove_conditions/test_seeder_lt.yml | 8 ++++++++ 13 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_gt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_lt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_gt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_lt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_connected_leecher_gt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_connected_leecher_lt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_connected_seeder_gt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_connected_seeder_lt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_leecher_gt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_leecher_lt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_seeder_gt.yml create mode 100644 pytest/test_strategies/cases/remove_conditions/test_seeder_lt.yml diff --git a/autoremovetorrents/conditionparser.py b/autoremovetorrents/conditionparser.py index eb95417..9cc57c4 100644 --- a/autoremovetorrents/conditionparser.py +++ b/autoremovetorrents/conditionparser.py @@ -1,24 +1,36 @@ import ply.yacc as yacc from . import logger -from .conditionlexer import ConditionLexer +from .condition.avgdownloadspeed import AverageDownloadSpeedCondition +from .condition.avguploadspeed import AverageUploadSpeedCondition from .condition.base import Comparer +from .condition.connectedleecher import ConnectedLeecherCondition +from .condition.connectedseeder import ConnectedSeederCondition from .condition.createtime import CreateTimeCondition from .condition.downloadspeed import DownloadSpeedCondition from .condition.lastactivity import LastActivityCondition +from .condition.leecher import LeecherCondition from .condition.ratio import RatioCondition +from .condition.seeder import SeederCondition from .condition.seedingtime import SeedingTimeCondition from .condition.size import SizeCondition from .condition.uploadspeed import UploadSpeedCondition +from .conditionlexer import ConditionLexer from .exception.nosuchcondition import NoSuchCondition from .exception.syntaxerror import ConditionSyntaxError class ConditionParser(object): # Condition Map (as constant) _condition_map = { + 'average_downloadspeed': AverageDownloadSpeedCondition, + 'average_uploadspeed': AverageUploadSpeedCondition, + 'connected_leecher': ConnectedLeecherCondition, + 'connected_seeder': ConnectedSeederCondition, 'create_time': CreateTimeCondition, 'download_speed': DownloadSpeedCondition, 'last_activity': LastActivityCondition, + 'leecher': LeecherCondition, 'ratio': RatioCondition, + 'seeder': SeederCondition, 'seeding_time': SeedingTimeCondition, 'size': SizeCondition, 'upload_speed': UploadSpeedCondition, diff --git a/pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_gt.yml b/pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_gt.yml new file mode 100644 index 0000000..a43e8ae --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_gt.yml @@ -0,0 +1,4 @@ +test: + remove: average_downloadspeed > 9800 +remove: + - Torrent - 13 diff --git a/pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_lt.yml b/pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_lt.yml new file mode 100644 index 0000000..36c9898 --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_average_downloadspeed_lt.yml @@ -0,0 +1,5 @@ +test: + remove: average_downloadspeed < 500 +remove: + - Torrent - 1 + - Torrent - 2 diff --git a/pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_gt.yml b/pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_gt.yml new file mode 100644 index 0000000..63dbdff --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_gt.yml @@ -0,0 +1,5 @@ +test: + remove: average_uploadspeed > 900 +remove: + - Torrent - 15 + - Torrent - 16 diff --git a/pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_lt.yml b/pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_lt.yml new file mode 100644 index 0000000..699a426 --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_average_uploadspeed_lt.yml @@ -0,0 +1,5 @@ +test: + remove: average_uploadspeed < 100 +remove: + - Torrent - 1 + - Torrent - 6 diff --git a/pytest/test_strategies/cases/remove_conditions/test_connected_leecher_gt.yml b/pytest/test_strategies/cases/remove_conditions/test_connected_leecher_gt.yml new file mode 100644 index 0000000..8997f2c --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_connected_leecher_gt.yml @@ -0,0 +1,4 @@ +test: + remove: connected_leecher > 100 +remove: + - Torrent - 1 diff --git a/pytest/test_strategies/cases/remove_conditions/test_connected_leecher_lt.yml b/pytest/test_strategies/cases/remove_conditions/test_connected_leecher_lt.yml new file mode 100644 index 0000000..68f1bd4 --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_connected_leecher_lt.yml @@ -0,0 +1,7 @@ +test: + remove: connected_leecher < 1 +remove: + - Torrent - 3 + - Torrent - 4 + - Torrent - 7 + - Torrent - 9 diff --git a/pytest/test_strategies/cases/remove_conditions/test_connected_seeder_gt.yml b/pytest/test_strategies/cases/remove_conditions/test_connected_seeder_gt.yml new file mode 100644 index 0000000..5c12dba --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_connected_seeder_gt.yml @@ -0,0 +1,5 @@ +test: + remove: connected_seeder > 0 +remove: + - Torrent - 1 + - Torrent - 12 diff --git a/pytest/test_strategies/cases/remove_conditions/test_connected_seeder_lt.yml b/pytest/test_strategies/cases/remove_conditions/test_connected_seeder_lt.yml new file mode 100644 index 0000000..f6086bb --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_connected_seeder_lt.yml @@ -0,0 +1,13 @@ +test: + remove: connected_seeder < 1 +remove: + - Torrent - 2 + - Torrent - 3 + - Torrent - 4 + - Torrent - 5 + - Torrent - 6 + - Torrent - 7 + - Torrent - 8 + - Torrent - 9 + - Torrent - 10 + - Torrent - 11 diff --git a/pytest/test_strategies/cases/remove_conditions/test_leecher_gt.yml b/pytest/test_strategies/cases/remove_conditions/test_leecher_gt.yml new file mode 100644 index 0000000..14315fd --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_leecher_gt.yml @@ -0,0 +1,4 @@ +test: + remove: leecher > 100 +remove: + - Torrent - 1 diff --git a/pytest/test_strategies/cases/remove_conditions/test_leecher_lt.yml b/pytest/test_strategies/cases/remove_conditions/test_leecher_lt.yml new file mode 100644 index 0000000..8f37ee9 --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_leecher_lt.yml @@ -0,0 +1,10 @@ +test: + remove: leecher < 10 +remove: + - Torrent - 4 + - Torrent - 5 + - Torrent - 7 + - Torrent - 8 + - Torrent - 9 + - Torrent - 13 + - Torrent - 14 diff --git a/pytest/test_strategies/cases/remove_conditions/test_seeder_gt.yml b/pytest/test_strategies/cases/remove_conditions/test_seeder_gt.yml new file mode 100644 index 0000000..0809e32 --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_seeder_gt.yml @@ -0,0 +1,14 @@ +test: + remove: seeder > 1 +remove: + - Torrent - 3 + - Torrent - 4 + - Torrent - 5 + - Torrent - 6 + - Torrent - 7 + - Torrent - 8 + - Torrent - 9 + - Torrent - 10 + - Torrent - 13 + - Torrent - 14 + - Torrent - 16 diff --git a/pytest/test_strategies/cases/remove_conditions/test_seeder_lt.yml b/pytest/test_strategies/cases/remove_conditions/test_seeder_lt.yml new file mode 100644 index 0000000..6408a3e --- /dev/null +++ b/pytest/test_strategies/cases/remove_conditions/test_seeder_lt.yml @@ -0,0 +1,8 @@ +test: + remove: seeder < 2 +remove: + - Torrent - 1 + - Torrent - 2 + - Torrent - 11 + - Torrent - 12 + - Torrent - 15