1#!/usr/bin/python3
2#
3# Copyright (C) 2023 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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 under
15# the License.
16#
17import filecmp
18import os
19import tempfile
20import unittest
21
22import compare_cts_reports
23import parse_cts_report
24
25
26class TestParse(unittest.TestCase):
27
28  def test_one_way(self):
29    ctsreports = [
30        parse_cts_report.parse_report_file('testdata/test_result_1.xml'),
31        parse_cts_report.parse_report_file('testdata/test_result_2.xml'),
32    ]
33    with tempfile.TemporaryDirectory() as temp_dir:
34      csvfile = os.path.join(temp_dir, 'one_way_diff.csv')
35      compare_cts_reports.one_way_compare(ctsreports, csvfile)
36
37      self.assertTrue(filecmp.cmp('testdata/compare/one_way_diff.csv', csvfile))
38
39  def test_two_way(self):
40    ctsreports = [
41        parse_cts_report.parse_report_file('testdata/test_result_1.xml'),
42        parse_cts_report.parse_report_file('testdata/test_result_2.xml'),
43    ]
44    with tempfile.TemporaryDirectory() as temp_dir:
45      csvfile = os.path.join(temp_dir, 'two_way_diff.csv')
46      compare_cts_reports.two_way_compare(ctsreports, csvfile)
47
48      self.assertTrue(filecmp.cmp('testdata/compare/two_way_diff.csv', csvfile))
49
50  def test_n_way(self):
51    ctsreports = [
52        parse_cts_report.parse_report_file('testdata/test_result_1.xml'),
53        parse_cts_report.parse_report_file('testdata/test_result_2.xml'),
54    ]
55    with tempfile.TemporaryDirectory() as temp_dir:
56      csvfile = os.path.join(temp_dir, 'n_way_diff.csv')
57      compare_cts_reports.n_way_compare(ctsreports, csvfile)
58
59      self.assertTrue(filecmp.cmp('testdata/compare/n_way_diff.csv', csvfile))
60
61
62if __name__ == '__main__':
63  unittest.main()
64