import fnmatch


def GetTestsFromDevice(runner):
  """Get a list of tests from a device, excluding disabled tests.

  Args:
    runner: a TestRunner.
  """
  # The executable/apk needs to be copied before we can call GetAllTests.
  runner.test_package.StripAndCopyExecutable()
  all_tests = runner.test_package.GetAllTests()
  # Only includes tests that do not have any match in the disabled list.
  disabled_list = runner.GetDisabledTests()
  return filter(lambda t: not any([fnmatch.fnmatch(t, disabled_pattern)
                                   for disabled_pattern in disabled_list]),
                all_tests)