Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the possibility to disable a task #3417

Merged
merged 5 commits into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
{
"type": "TransferPokemon"
},
{
"type": "NicknamePokemon",
"config": {
"enabled": false,
"nickname_template": "{iv_pct}_{iv_ads}"
}
},
{
"type": "EvolvePokemon",
"config": {
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def __init__(self, bot, config):
self.config = config
self._validate_work_exists()
self.logger = logging.getLogger(type(self).__name__)
self.enabled = config.get('enabled', True)
self.initialize()

def _validate_work_exists(self):
Expand Down
3 changes: 2 additions & 1 deletion pokemongo_bot/tree_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def build(self):
)

instance = worker(self.bot, task_config)
workers.append(instance)
if instance.enabled:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unittest for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

workers.append(instance)

return workers

19 changes: 19 additions & 0 deletions tests/tree_config_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ def test_task_with_config(self):
tree = builder.build()
self.assertTrue(tree[0].config.get('longer_eggs_first', False))

def test_disabling_task(self):
obj = convert_from_json("""[{
"type": "HandleSoftBan",
"config": {
"enabled": false
}
}, {
"type": "CatchLuredPokemon",
"config": {
"enabled": true
}
}]""")

builder = TreeConfigBuilder(self.bot, obj)
tree = builder.build()

self.assertTrue(len(tree) == 1)
self.assertIsInstance(tree[0], CatchLuredPokemon)

def test_load_plugin_task(self):
package_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resources', 'plugin_fixture')
plugin_loader = PluginLoader()
Expand Down