Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 3 | # Copyright 2013 IBM Corp. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # 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, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import sys |
| 18 | |
| 19 | |
| 20 | def filter_classes(test_ids): |
| 21 | test_classes = map(lambda x: x.rsplit('.', 1)[0], test_ids) |
| 22 | |
| 23 | #Remove duplicates from the list |
| 24 | uniq_class = {} |
| 25 | result = [] |
| 26 | for test_class in test_classes: |
| 27 | if test_class in uniq_class: |
| 28 | continue |
| 29 | uniq_class[test_class] = 1 |
| 30 | result.append(test_class) |
| 31 | return result |
| 32 | |
| 33 | |
| 34 | def usage(): |
| 35 | msg = """ |
| 36 | This command is used to filter out the unique list of test cases (classes) |
| 37 | from a list of testr test_ids. |
| 38 | |
| 39 | Usage: run_test_classes.py <test id file> |
| 40 | """ |
| 41 | print(msg) |
| 42 | sys.exit(1) |
| 43 | |
| 44 | |
| 45 | def main(): |
| 46 | if len(sys.argv) == 2: |
| 47 | test_list_path = sys.argv[1] |
| 48 | test_list_file = open(test_list_path, 'r') |
| 49 | test_list = test_list_file.readlines() |
| 50 | for test_class in filter_classes(test_list): |
| 51 | print test_class |
| 52 | test_list_file.close() |
| 53 | else: |
| 54 | usage() |
| 55 | |
| 56 | if __name__ == '__main__': |
| 57 | main() |