[Notes] [Git][BuildStream/buildstream][chiaratolentino/bst-init-interactive-elementpath] _frontend/app.py: Set correct element-path in interactive bst-init



Title: GitLab

Chiara Tolentino pushed to branch chiaratolentino/bst-init-interactive-elementpath at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_frontend/app.py
    ... ... @@ -305,7 +305,6 @@ class App():
    305 305
             directory = self._main_options['directory']
    
    306 306
             directory = os.path.abspath(directory)
    
    307 307
             project_path = os.path.join(directory, 'project.conf')
    
    308
    -        elements_path = os.path.join(directory, element_path)
    
    309 308
     
    
    310 309
             try:
    
    311 310
                 # Abort if the project.conf already exists, unless `--force` was specified in `bst init`
    
    ... ... @@ -335,6 +334,7 @@ class App():
    335 334
                     raise AppError("Error creating project directory {}: {}".format(directory, e)) from e
    
    336 335
     
    
    337 336
                 # Create the elements sub-directory if it doesnt exist
    
    337
    +            elements_path = os.path.join(directory, element_path)
    
    338 338
                 try:
    
    339 339
                     os.makedirs(elements_path, exist_ok=True)
    
    340 340
                 except IOError as e:
    

  • tests/frontend/init.py
    ... ... @@ -3,6 +3,7 @@ import pytest
    3 3
     from tests.testutils import cli
    
    4 4
     
    
    5 5
     from buildstream import _yaml
    
    6
    +from buildstream._frontend.app import App
    
    6 7
     from buildstream._exceptions import ErrorDomain, LoadErrorReason
    
    7 8
     from buildstream._versions import BST_FORMAT_VERSION
    
    8 9
     
    
    ... ... @@ -98,3 +99,34 @@ def test_bad_element_path(cli, tmpdir, element_path):
    98 99
             'init', '--project-name', 'foo', '--element-path', element_path
    
    99 100
         ])
    
    100 101
         result.assert_main_error(ErrorDomain.APP, 'invalid-element-path')
    
    102
    +
    
    103
    +
    
    104
    +@pytest.mark.parametrize("element_path", [('foo'), ('foo/bar')])
    
    105
    +def test_element_path_interactive(cli, tmp_path, monkeypatch, element_path):
    
    106
    +    project = tmp_path
    
    107
    +    project_conf_path = project.joinpath('project.conf')
    
    108
    +
    
    109
    +    class DummyInteractiveApp(App):
    
    110
    +        def __init__(self, *args, **kwargs):
    
    111
    +            super().__init__(*args, **kwargs)
    
    112
    +            self.interactive = True
    
    113
    +
    
    114
    +        @classmethod
    
    115
    +        def create(cls, *args, **kwargs):
    
    116
    +            return DummyInteractiveApp(*args, **kwargs)
    
    117
    +
    
    118
    +        def _init_project_interactive(self, *args, **kwargs):
    
    119
    +            return ('project_name', '0', element_path)
    
    120
    +
    
    121
    +    monkeypatch.setattr(App, 'create', DummyInteractiveApp.create)
    
    122
    +
    
    123
    +    result = cli.run(project=str(project), args=['init'])
    
    124
    +    result.assert_success()
    
    125
    +
    
    126
    +    full_element_path = project.joinpath(element_path)
    
    127
    +    assert full_element_path.exists()
    
    128
    +
    
    129
    +    project_conf = _yaml.load(str(project_conf_path))
    
    130
    +    assert project_conf['name'] == 'project_name'
    
    131
    +    assert project_conf['format-version'] == '0'
    
    132
    +    assert project_conf['element-path'] == element_path



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]