#!/usr/bin/env python # 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/. import unittest import mozunit from taskcluster_graph.commit_parser import ( parse_commit, normalize_test_list, InvalidCommitException ) class TestCommitParser(unittest.TestCase): def test_normalize_test_list_none(self): self.assertEqual( normalize_test_list(['woot'], 'none'), [] ) def test_normalize_test_list_all(self): self.assertEqual( normalize_test_list(['woot'], 'all'), [{ 'test': 'woot' }] ) def test_normalize_test_list_specific_tests(self): self.assertEqual( normalize_test_list(['woot'], 'a,b,c'), [{ 'test': 'a' }, { 'test': 'b' }, { 'test': 'c' }] ) def test_normalize_test_list_specific_tests_with_whitespace(self): self.assertEqual( normalize_test_list(['woot'], 'a, b, c'), [{ 'test': 'a' }, { 'test': 'b' }, { 'test': 'c' }] ) def test_invalid_commit(self): ''' Disallow invalid commit messages from being parsed... ''' with self.assertRaises(InvalidCommitException): parse_commit("wootbarbaz", {}) def test_commit_no_tests(self): ''' This test covers the case of builds but no tests passed -u none ''' commit = 'try: -b o -p linux -u none -t none' jobs = { 'flags': { 'builds': ['linux', 'linux64'], 'tests': ['web-platform-tests'], }, 'builds': { 'linux': { 'types': { 'opt': 'task/linux', 'debug': 'task/linux-debug' } }, }, 'tests': {} } expected = [ { 'task': 'task/linux', 'dependents': [] } ] result = parse_commit(commit, jobs) self.assertEqual(expected, result) def test_commit_all_builds_no_tests(self): ''' This test covers the case of all builds but no tests passed -u none ''' commit = 'try: -b o -p all -u none -t none' jobs = { 'flags': { 'builds': ['linux', 'linux64'], 'tests': ['web-platform-tests'], }, 'builds': { 'linux': { 'types': { 'opt': 'task/linux', 'debug': 'task/linux-debug' } }, }, 'tests': {} } expected = [ { 'task': 'task/linux', 'dependents': [] } ] result = parse_commit(commit, jobs) self.assertEqual(expected, result) def test_some_test_tasks_restricted(self): ''' This test covers the case of all builds but no tests passed -u none ''' commit = 'try: -b do -p all -u all -t none' jobs = { 'flags': { 'builds': ['linux', 'linux64'], 'tests': ['web-platform-tests'], }, 'builds': { 'linux': { 'types': { 'opt': 'task/linux', 'debug': 'task/linux-debug' } }, }, 'tests': { 'web-platform-tests': { 'task': 'task/web-platform-tests', 'allowed_build_tasks': [ 'task/linux' ] } } } expected = [ { 'task': 'task/linux-debug', 'dependents': [] }, { 'task': 'task/linux', 'dependents': [{ 'task': 'task/web-platform-tests', 'allowed_build_tasks': ['task/linux'] }] } ] result = parse_commit(commit, jobs) self.assertEqual(expected, result) def test_specific_test_platforms(self): ''' This test cases covers the platform specific test exclusion options. ''' commit = 'try: -b od -p all -u all[windows,b2g] -t none' jobs = { 'flags': { 'builds': ['linux', 'win32'], 'tests': ['web-platform-tests', 'mochitest'], }, 'builds': { 'linux': { 'types': { 'opt': 'task/linux', 'debug': 'task/linux-debug' } }, 'win32': { 'platforms': ['windows'], 'types': { 'opt': 'task/win32', } }, }, 'tests': { 'web-platform-tests': { 'task': 'task/web-platform-tests', }, 'mochitest': { 'task': 'task/mochitest', } } } expected = [ { 'task': 'task/linux', 'dependents': [] }, { 'task': 'task/linux-debug', 'dependents': [] }, { 'task': 'task/win32', 'dependents': [ { 'task': 'task/web-platform-tests' }, { 'task': 'task/mochitest' } ] } ] result = parse_commit(commit, jobs) self.assertEqual(expected, result) def test_specific_test_platforms_with_specific_platform(self): ''' This test cases covers the platform specific test exclusion options. ''' commit = 'try: -b od -p win32 -u mochitest[windows] -t none' jobs = { 'flags': { 'builds': ['linux', 'win32'], 'tests': ['web-platform-tests', 'mochitest'], }, 'builds': { 'linux': { 'types': { 'opt': 'task/linux', 'debug': 'task/linux-debug' } }, 'win32': { 'platforms': ['windows'], 'types': { 'opt': 'task/win32', } }, }, 'tests': { 'web-platform-tests': { 'task': 'task/web-platform-tests', }, 'mochitest': { 'task': 'task/mochitest', } } } expected = [ { 'task': 'task/win32', 'dependents': [ { 'task': 'task/mochitest' } ] } ] result = parse_commit(commit, jobs) self.assertEqual(expected, result) def test_commit_with_builds_and_tests(self): ''' This test covers the broad case of a commit which has both builds and tests without any exclusions or other fancy logic. ''' commit = 'try: -b od -p linux,linux64 -u web-platform-tests -t none' jobs = { 'flags': { 'builds': ['linux', 'linux64'], 'tests': ['web-platform-tests'], }, 'builds': { 'linux': { 'types': { 'opt': 'task/linux', 'debug': 'task/linux-debug' } }, 'linux64': { 'types': { 'opt': 'task/linux64', 'debug': 'task/linux64-debug' } } }, 'tests': { 'web-platform-tests': { 'task': 'task/web-platform-tests' } } } expected = [ { 'task': 'task/linux', 'dependents': [ { 'task': 'task/web-platform-tests' } ] }, { 'task': 'task/linux-debug', 'dependents': [ { 'task': 'task/web-platform-tests' } ] }, { 'task': 'task/linux64', 'dependents': [ { 'task': 'task/web-platform-tests' } ] }, { 'task': 'task/linux64-debug', 'dependents': [ { 'task': 'task/web-platform-tests' } ] } ] result = parse_commit(commit, jobs) self.assertEqual(expected, result) if __name__ == '__main__': mozunit.main()