blob: 6e9a6cae70e0c4a5c35968500074b147eef1ac4a [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for"""
from __future__ import print_function
import os
import sys
from chromite.lib import cros_test_lib
from chromite.lib import osutils
from chromite.lib import unittest_lib
from chromite.scripts import dep_tracker
pytestmark = cros_test_lib.pytestmark_inside_only
assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
# Allow access private members for testing:
# pylint: disable=protected-access
class MainTest(cros_test_lib.OutputTestCase):
"""Tests for the main() function."""
def testHelp(self):
"""Test that --help is functioning."""
argv = ['--help']
with self.OutputCapturer() as output:
# Running with --help should exit with code==0.
self.AssertFuncSystemExitZero(dep_tracker.main, argv)
# Verify that a message beginning with "usage: " was printed.
stdout = output.GetStdout()
self.assertTrue(stdout.startswith('usage: '))
class DepTrackerTest(cros_test_lib.TempDirTestCase):
"""Tests for the DepTracker() class."""
def testSimpleDep(self):
unittest_lib.BuildELF(os.path.join(self.tempdir, ''),
['func_a', 'func_b', 'func_c'])
unittest_lib.BuildELF(os.path.join(self.tempdir, 'abc_main'),
dt = dep_tracker.DepTracker(self.tempdir)
self.assertEqual(sorted(dt._files.keys()), ['abc_main', ''])
def testFiletypeSet(self):
"""Tests that the 'ftype' member is set for ELF files first."""
unittest_lib.BuildELF(os.path.join(self.tempdir, ''),
['func_a', 'func_b', 'func_c'])
osutils.WriteFile(os.path.join(self.tempdir, 'pyscript'),
'#!/usr/bin/python\nimport sys\nsys.exit(42)\n')
dt = dep_tracker.DepTracker(self.tempdir)
# ComputeELFFileDeps() should compute the file type of ELF files so we
# don't need to parse them again.
self.assertTrue('ftype' in dt._files[''])
self.assertFalse('ftype' in dt._files['pyscript'])
# ComputeFileTypes() shold compute the file type of every file.
self.assertTrue('ftype' in dt._files[''])
self.assertTrue('ftype' in dt._files['pyscript'])