Skip to content

Commit

Permalink
Give the possibility to disable a task without removing it (#3417)
Browse files Browse the repository at this point in the history
* Give the possiblity to disable a task in config without removing it from the config file

* Put exmple only in nickname task

* Add Unit testing

* typo

* Use enabled false as exemple
  • Loading branch information
achretien authored and elicwhite committed Aug 10, 2016
1 parent 72622b4 commit 558540e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
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": {

This comment has been minimized.

Copy link
@nearalias

nearalias Aug 10, 2016

this isn't in code yet right? but isn't it redundant because having the task in config means it's enabled, like every other tasks

"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:
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

0 comments on commit 558540e

Please sign in to comment.