|
1 | 1 | import io
|
| 2 | +import os |
2 | 3 | import sys
|
3 | 4 | import pytest
|
4 | 5 | from unittest import mock
|
@@ -136,3 +137,34 @@ def test_recipes(self):
|
136 | 137 | assert expected_string in m_stdout.getvalue()
|
137 | 138 | # deletes static attribute to not mess with other tests
|
138 | 139 | del Recipe.recipes
|
| 140 | + |
| 141 | + def test_local_recipes_dir(self): |
| 142 | + """ |
| 143 | + Checks the `local_recipes` attribute in the Context is absolute. |
| 144 | + """ |
| 145 | + cwd = os.path.realpath(os.getcwd()) |
| 146 | + common_args = [ |
| 147 | + 'toolchain.py', |
| 148 | + 'recommendations', |
| 149 | + ] |
| 150 | + |
| 151 | + # Check the default ./p4a-recipes becomes absolute. |
| 152 | + argv = common_args |
| 153 | + with patch_sys_argv(argv): |
| 154 | + toolchain = ToolchainCL() |
| 155 | + expected_local_recipes = os.path.join(cwd, 'p4a-recipes') |
| 156 | + assert toolchain.ctx.local_recipes == expected_local_recipes |
| 157 | + |
| 158 | + # Check a supplied relative directory becomes absolute. |
| 159 | + argv = common_args + ['--local-recipes=foo'] |
| 160 | + with patch_sys_argv(argv): |
| 161 | + toolchain = ToolchainCL() |
| 162 | + expected_local_recipes = os.path.join(cwd, 'foo') |
| 163 | + assert toolchain.ctx.local_recipes == expected_local_recipes |
| 164 | + |
| 165 | + # An absolute directory should remain unchanged. |
| 166 | + local_recipes = os.path.join(cwd, 'foo') |
| 167 | + argv = common_args + ['--local-recipes={}'.format(local_recipes)] |
| 168 | + with patch_sys_argv(argv): |
| 169 | + toolchain = ToolchainCL() |
| 170 | + assert toolchain.ctx.local_recipes == local_recipes |
0 commit comments