test_files_changed.py (1963B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 import unittest 7 8 from mozunit import main 9 10 from gecko_taskgraph import files_changed 11 12 PARAMS = { 13 "head_repository": "https://hg.mozilla.org/mozilla-central", 14 "head_rev": "a14f88a9af7a", 15 } 16 17 FILES_CHANGED = [ 18 "devtools/client/debugger/index.html", 19 "devtools/client/inspector/test/browser_inspector_highlighter-eyedropper-events.js", 20 "devtools/client/inspector/test/head.js", 21 "devtools/client/themes/rules.css", 22 "devtools/client/webconsole/test/browser_webconsole_output_06.js", 23 "devtools/server/actors/highlighters/eye-dropper.js", 24 "devtools/server/actors/object.js", 25 "docshell/base/nsDocShell.cpp", 26 "dom/tests/mochitest/general/test_contentViewer_overrideDPPX.html", 27 "taskcluster/scripts/builder/build-l10n.sh", 28 ] 29 30 31 def test_get_changed_files(responses): 32 url = f"{PARAMS['head_repository']}/json-pushchangedfiles/{PARAMS['head_rev']}" 33 responses.add(responses.GET, url, status=200, json={"files": FILES_CHANGED}) 34 assert ( 35 sorted( 36 files_changed.get_changed_files( 37 PARAMS["head_repository"], PARAMS["head_rev"] 38 ) 39 ) 40 == FILES_CHANGED 41 ) 42 43 44 class TestCheck(unittest.TestCase): 45 def setUp(self): 46 files_changed.get_changed_files[ 47 PARAMS["head_repository"], PARAMS["head_rev"] 48 ] = FILES_CHANGED 49 50 def tearDown(self): 51 files_changed.get_changed_files.clear() 52 53 def test_check_no_params(self): 54 self.assertTrue(files_changed.check({}, ["ignored"])) 55 56 def test_check_no_match(self): 57 self.assertFalse(files_changed.check(PARAMS, ["nosuch/**"])) 58 59 def test_check_match(self): 60 self.assertTrue(files_changed.check(PARAMS, ["devtools/**"])) 61 62 63 if __name__ == "__main__": 64 main()