aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/tests/utils.py
blob: 0a969964b5d9e3b633b4198f681e79964146a3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python

# Copyright 2014 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Common code for tests.
"""
import filecmp
import os

EXPECTATIONS_DIR = os.path.join(os.path.dirname(__file__), 'expectations')

def compare_to_expectation(actual_name, expectation_name, assert_true,
                           msg=None):
  """Check that a generated file matches its expectation in EXPECTATIONS_DIR.

  Assert that the generated file and expectation file are identical.

  Args:
      actual_name: Full path to the test file.
      expectation_name: Basename of the expectations file within which
          to compare. The file is expected to be in
          platform_tools/android/tests/expectations.
      assert_true: function for asserting a statement is True

      Args:
          condition: statement to check for True.
          msg: message to print if the files are not equal.

      msg: Message to pass to assert_true.
  """
  full_expectations_path = os.path.join(EXPECTATIONS_DIR, expectation_name)
  assert_true(filecmp.cmp(actual_name, full_expectations_path), msg)