diff options
| author | Bernardas AliĊĦauskas <bernardas.alisauskas@pm.me> | 2021-09-27 17:12:22 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-27 13:12:22 +0300 |
| commit | edde6029745a650696773c30247b97c151079487 (patch) | |
| tree | e04a1580cf96e7d018d1a1ac4e63333d8cd7c4b9 /tests/test_taskipy.py | |
| parent | Release version 1.8.2 (diff) | |
| download | taskipy2-edde6029745a650696773c30247b97c151079487.zip | |
Add variable support (#38)
* add variable support
* add use_vars task option and make command variables expand only when use_vars is True
* add tests for variable feature
* add setting use_vars as global use_vars for all commands
Diffstat (limited to 'tests/test_taskipy.py')
| -rw-r--r-- | tests/test_taskipy.py | 95 |
1 files changed, 94 insertions, 1 deletions
diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py index 1598f0f..4a1c3e3 100644 --- a/tests/test_taskipy.py +++ b/tests/test_taskipy.py @@ -272,7 +272,7 @@ class TaskDescriptionTestCase(TaskipyTestCase): exit_code, stdout, _ = self.run_task('print_age', cwd=cwd) self.assertEqual(exit_code, 1) - self.assertSubstr('tasks must be strings, or dicts that contain { cmd, help }', stdout) + self.assertSubstr('tasks must be strings, or dicts that contain { cmd, help, use_vars }', stdout) class TaskRunFailTestCase(TaskipyTestCase): @@ -429,3 +429,96 @@ class TaskFromChildTestCase(TaskipyTestCase): _, stdout, _ = self.run_task('hello', cwd=path.join(cwd, 'child_with_pyproject')) self.assertSubstr('hello from child', stdout) + + +class UseVarsTestCase(TaskipyTestCase): + def test_use_vars_working(self): + py_project_toml = ''' + [tool.taskipy.variables] + name = "John Doe" + + [tool.taskipy.tasks] + echo = { cmd = "echo hello {name:<10}:", use_vars=true } + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr('hello John Doe :', stdout) + self.assertEqual(exit_code, 0) + + def test_use_vars_no_param(self): + py_project_toml = ''' + [tool.taskipy.variables] + name = "John Doe" + + [tool.taskipy.tasks] + echo = { cmd = "echo hello {name}" } + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr('hello {name}', stdout) + self.assertEqual(exit_code, 0) + + def test_use_vars_param_disabled(self): + py_project_toml = ''' + [tool.taskipy.variables] + name = "John Doe" + + [tool.taskipy.tasks] + echo = { cmd = "echo hello {name}", use_vars=false} + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr('hello {name}', stdout) + self.assertEqual(exit_code, 0) + + def test_use_vars_str_task_no_param(self): + py_project_toml = ''' + [tool.taskipy.variables] + name = "John Doe" + + [tool.taskipy.tasks] + echo = "echo hello {name}" + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr('hello {name}', stdout) + self.assertEqual(exit_code, 0) + + def test_use_vars_param_malformed(self): + py_project_toml = ''' + [tool.taskipy.variables] + name = "John Doe" + + [tool.taskipy.tasks] + echo = { cmd = "echo hello {name}", use_vars=1} + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr('task\'s "use_vars" arg has to be bool', stdout) + self.assertEqual(exit_code, 1) + + def test_use_vars_missing_var(self): + py_project_toml = ''' + [tool.taskipy.tasks] + echo = { cmd = "echo hello {name}", use_vars=true} + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr("reason: 'name' variable expected in [pyproject.taskipy.variables", stdout) + self.assertEqual(exit_code, 1) + + def test_use_vars_setting(self): + py_project_toml = ''' + [tool.taskipy.settings] + use_vars = true + + [tool.taskipy.variables] + name = "John Doe" + + [tool.taskipy.tasks] + echo = "echo hello {name:<10}:" + ''' + cwd = self.create_test_dir_with_py_project_toml(py_project_toml) + exit_code, stdout, _ = self.run_task('echo', cwd=cwd) + self.assertSubstr('hello John Doe :', stdout) + self.assertEqual(exit_code, 0) |