| Conditions | 3 |
| Total Lines | 59 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """ |
||
| 95 | def test_plugin_ok(self): |
||
| 96 | """Install a good plugin and test it""" |
||
| 97 | |||
| 98 | clean_plugin_dir() |
||
| 99 | |||
| 100 | folder = __venv_dir__ + '/plugins/test_plugin' |
||
| 101 | os.mkdir(folder) |
||
| 102 | os.mkdir(folder + '/test_plugin') |
||
| 103 | |||
| 104 | # Add setup |
||
| 105 | with open(folder + '/setup.py', 'w') as file: |
||
| 106 | file.write(r"""from setuptools import setup |
||
| 107 | |||
| 108 | setup( |
||
| 109 | name='StakkrTestPlugin', |
||
| 110 | version='3.5', |
||
| 111 | packages=['test_plugin'], |
||
| 112 | entry_points=''' |
||
| 113 | [stakkr.plugins] |
||
| 114 | test_plugin=test_plugin.core:my_test |
||
| 115 | ''' |
||
| 116 | ) |
||
| 117 | """) |
||
| 118 | |||
| 119 | # Add plugin content |
||
| 120 | with open(folder + '/test_plugin/core.py', 'w') as file: |
||
| 121 | file.write(r"""import click |
||
| 122 | |||
| 123 | @click.command(name="hello-world") |
||
| 124 | @click.pass_context |
||
| 125 | def my_test(ctx): |
||
| 126 | print('Hello test !') |
||
| 127 | """) |
||
| 128 | |||
| 129 | # Refresh plugins, plugin should be added |
||
| 130 | cmd = self.cmd_base + ['refresh-plugins'] |
||
| 131 | res = exec_cmd(cmd) |
||
| 132 | self.assertRegex(res['stdout'], '.*Adding plugins from plugins.*') |
||
| 133 | self.assertRegex(res['stdout'], '.*Plugin "test_plugin" added.*') |
||
| 134 | self.assertEqual(res['stderr'], '') |
||
| 135 | self.assertIs(res['status'], 0) |
||
| 136 | |||
| 137 | # Plugin installed, command available ! |
||
| 138 | cmd = self.cmd_base + ['hello-world'] |
||
| 139 | res = exec_cmd(cmd) |
||
| 140 | self.assertEqual(res['stdout'], 'Hello test !') |
||
| 141 | self.assertEqual(res['stderr'], '') |
||
| 142 | self.assertIs(res['status'], 0) |
||
| 143 | |||
| 144 | # Now it should remove |
||
| 145 | cmd = self.cmd_base + ['refresh-plugins'] |
||
| 146 | res = exec_cmd(cmd) |
||
| 147 | self.assertRegex(res['stdout'], '.*Adding plugins from plugins.*') |
||
| 148 | self.assertRegex(res['stdout'], '.*Cleaning "StakkrTestPlugin".*') |
||
| 149 | self.assertRegex(res['stdout'], '.*Plugin "test_plugin" added.*') |
||
| 150 | self.assertEqual(res['stderr'], '') |
||
| 151 | self.assertIs(res['status'], 0) |
||
| 152 | |||
| 153 | rmtree(folder) |
||
| 154 | |||
| 185 |