Bug 1533474 - [fuzzy] Fix paths with |mach try fuzzy|, r=gbrown
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 08 Mar 2019 00:12:41 +0000
changeset 520948 c4d22c2dae9c
parent 520947 e68932c65a3f
child 520949 3e844ef9583b
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1533474, 1531886
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533474 - [fuzzy] Fix paths with |mach try fuzzy|, r=gbrown This fixes a regression from bug 1531886 and adds a test. Differential Revision: https://phabricator.services.mozilla.com/D22575
tools/tryselect/mach_commands.py
tools/tryselect/selectors/fuzzy.py
tools/tryselect/test/conftest.py
tools/tryselect/test/python.ini
tools/tryselect/test/test_fuzzy.py
tools/tryselect/test/test_presets.py
--- a/tools/tryselect/mach_commands.py
+++ b/tools/tryselect/mach_commands.py
@@ -244,16 +244,19 @@ class TrySelect(MachCommandBase):
         if kwargs.get('save') and not kwargs.get('query'):
             # If saving preset without -q/--query, allow user to use the
             # interface to build the query.
             kwargs_copy = kwargs.copy()
             kwargs_copy['push'] = False
             kwargs_copy['save'] = None
             kwargs['query'] = self.run(save_query=True, **kwargs_copy)
 
+        if kwargs.get('paths'):
+            kwargs['test_paths'] = kwargs['paths']
+
         return self.run(**kwargs)
 
     @SubCommand('try',
                 'chooser',
                 description='Schedule tasks by selecting them from a web '
                             'interface.',
                 parser=get_parser('chooser'))
     def try_chooser(self, **kwargs):
--- a/tools/tryselect/selectors/fuzzy.py
+++ b/tools/tryselect/selectors/fuzzy.py
@@ -207,33 +207,33 @@ def run_fzf(cmd, tasks):
     return query, selected
 
 
 def filter_target_task(task):
     return not any(re.search(pattern, task) for pattern in TARGET_TASK_FILTERS)
 
 
 def run(update=False, query=None, templates=None, full=False, parameters=None, save_query=False,
-        push=True, message='{msg}', paths=None, exact=False, closed_tree=False,
+        push=True, message='{msg}', test_paths=None, exact=False, closed_tree=False,
         intersection=False):
     fzf = fzf_bootstrap(update)
 
     if not fzf:
         print(FZF_NOT_FOUND)
         return 1
 
     check_working_directory(push)
     tg = generate_tasks(parameters, full, root=vcs.path)
     all_tasks = sorted(tg.tasks.keys())
 
     if not full:
         all_tasks = filter(filter_target_task, all_tasks)
 
-    if paths:
-        all_tasks = filter_tasks_by_paths(all_tasks, paths)
+    if test_paths:
+        all_tasks = filter_tasks_by_paths(all_tasks, test_paths)
         if not all_tasks:
             return 1
 
     key_shortcuts = [k + ':' + v for k, v in fzf_shortcuts.iteritems()]
     base_cmd = [
         fzf, '-m',
         '--bind', ','.join(key_shortcuts),
         '--header', format_header(),
@@ -276,16 +276,16 @@ def run(update=False, query=None, templa
         return
 
     if save_query:
         return queries
 
     # build commit message
     msg = "Fuzzy"
     args = []
-    if paths:
-        args.append("paths={}".format(':'.join(paths)))
+    if test_paths:
+        args.append("paths={}".format(':'.join(test_paths)))
     if query:
         args.extend(["query={}".format(q) for q in queries])
     if args:
         msg = "{} {}".format(msg, '&'.join(args))
     return push_to_try('fuzzy', message.format(msg=msg), selected, templates, push=push,
                        closed_tree=closed_tree)
--- a/tools/tryselect/test/conftest.py
+++ b/tools/tryselect/test/conftest.py
@@ -28,16 +28,31 @@ def patch_vcs(monkeypatch):
     attrs = {
         'path': push.vcs.path,
     }
     mock = MagicMock()
     mock.configure_mock(**attrs)
     monkeypatch.setattr(push, 'vcs', mock)
 
 
+@pytest.fixture(scope='session')
+def run_mach():
+    import mach_bootstrap
+    from mach.config import ConfigSettings
+    from tryselect.tasks import build
+
+    mach = mach_bootstrap.bootstrap(build.topsrcdir)
+
+    def inner(args):
+        mach.settings = ConfigSettings()
+        return mach.run(args)
+
+    return inner
+
+
 def pytest_generate_tests(metafunc):
     if all(fixture in metafunc.fixturenames for fixture in ('template', 'args', 'expected')):
         def load_tests():
             for template, tests in metafunc.module.TEMPLATE_TESTS.items():
                 for args, expected in tests:
                     yield (template, args, expected)
 
         tests = list(load_tests())
--- a/tools/tryselect/test/python.ini
+++ b/tools/tryselect/test/python.ini
@@ -1,8 +1,9 @@
 [DEFAULT]
 subsuite=try
 skip-if = python == 3
 
 [test_again.py]
+[test_fuzzy.py]
 [test_presets.py]
 [test_tasks.py]
 [test_templates.py]
new file mode 100644
--- /dev/null
+++ b/tools/tryselect/test/test_fuzzy.py
@@ -0,0 +1,33 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+import os
+
+import mozunit
+import pytest
+
+
+@pytest.mark.skipif(os.name == 'nt', reason="fzf not installed on host")
+def test_paths(run_mach, capfd):
+    cmd = ['try', 'fuzzy', '--no-push',
+           '-q', "'linux64/opt-xpcshell", 'caps/tests/unit/test_origin.js']
+    assert run_mach(cmd) == 0
+
+    output = capfd.readouterr().out
+    print(output)
+
+    # If there are more than one tasks here, it means that something went wrong
+    # with the path filtering.
+    expected = """
+    "tasks": [
+        "test-linux64/opt-xpcshell-1"
+    ]""".lstrip()
+
+    assert expected in output
+
+
+if __name__ == '__main__':
+    mozunit.main()
--- a/tools/tryselect/test/test_presets.py
+++ b/tools/tryselect/test/test_presets.py
@@ -1,31 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import mozunit
-import pytest
-
-
-@pytest.fixture(scope='session')
-def run_mach():
-    import mach_bootstrap
-    from mach.config import ConfigSettings
-    from tryselect.tasks import build
-
-    mach = mach_bootstrap.bootstrap(build.topsrcdir)
-
-    def inner(args):
-        mach.settings = ConfigSettings()
-        return mach.run(args)
-
-    return inner
 
 
 def test_shared_presets(run_mach, shared_name, shared_preset):
     """This test makes sure that we don't break any of the in-tree presets when
     renaming/removing variables in any of the selectors.
     """
     assert 'description' in shared_preset
     assert 'selector' in shared_preset