1#!/usr/bin/env python3 2# 3# Copyright 2018, The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18"""Unit tests for the args_utils.py script.""" 19 20import typing 21 22import args_utils 23 24def generate_run_combinations(*args): 25 # expand out the generator values so that assert x == y works properly. 26 return [i for i in args_utils.generate_run_combinations(*args)] 27 28def test_generate_run_combinations(): 29 blank_nd = typing.NamedTuple('Blank') 30 assert generate_run_combinations(blank_nd, {}, 1) == [()], "empty" 31 assert generate_run_combinations(blank_nd, {'a': ['a1', 'a2']}) == [ 32 ()], "empty filter" 33 a_nd = typing.NamedTuple('A', [('a', str)]) 34 assert generate_run_combinations(a_nd, {'a': None}) == [(None,)], "None" 35 assert generate_run_combinations(a_nd, {'a': ['a1', 'a2']}) == [('a1',), ( 36 'a2',)], "one item" 37 assert generate_run_combinations(a_nd, 38 {'a': ['a1', 'a2'], 'b': ['b1', 'b2']}) == [ 39 ('a1',), ('a2',)], \ 40 "one item filter" 41 assert generate_run_combinations(a_nd, {'a': ['a1', 'a2']}, 2) == [('a1',), ( 42 'a2',), ('a1',), ('a2',)], "one item" 43 ab_nd = typing.NamedTuple('AB', [('a', str), ('b', str)]) 44 assert generate_run_combinations(ab_nd, 45 {'a': ['a1', 'a2'], 46 'b': ['b1', 'b2']}) == [ab_nd('a1', 'b1'), 47 ab_nd('a1', 'b2'), 48 ab_nd('a2', 'b1'), 49 ab_nd('a2', 'b2')], \ 50 "two items" 51 52 assert generate_run_combinations(ab_nd, 53 {'as': ['a1', 'a2'], 54 'bs': ['b1', 'b2']}) == [ab_nd('a1', 'b1'), 55 ab_nd('a1', 'b2'), 56 ab_nd('a2', 'b1'), 57 ab_nd('a2', 'b2')], \ 58 "two items plural" 59