1# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import unittest
6
7from telemetry.util import matching
8
9
10class BenchmarkFoo(object):
11  """ Benchmark Foo for testing."""
12  @classmethod
13  def Name(cls):
14    return 'FooBenchmark'
15
16
17class BenchmarkBar(object):
18  """ Benchmark Bar for testing long description line."""
19  @classmethod
20  def Name(cls):
21    return 'BarBenchmarkkkkk'
22
23
24class UnusualBenchmark(object):
25  @classmethod
26  def Name(cls):
27    return 'I have a very unusual name'
28
29
30class CommandLineUnittest(unittest.TestCase):
31  def testGetMostLikelyMatchedObject(self):
32    # Test moved from telemetry/benchmark_runner_unittest.py
33    all_benchmarks = [BenchmarkFoo, BenchmarkBar, UnusualBenchmark]
34    self.assertEquals(
35        [BenchmarkFoo, BenchmarkBar],
36        matching.GetMostLikelyMatchedObject(
37            all_benchmarks, 'BenchmarkFooz', name_func=lambda x: x.Name()))
38
39    self.assertEquals(
40        [BenchmarkBar, BenchmarkFoo],
41        matching.GetMostLikelyMatchedObject(
42            all_benchmarks, 'BarBenchmark', name_func=lambda x: x.Name()))
43
44    self.assertEquals(
45        [UnusualBenchmark],
46        matching.GetMostLikelyMatchedObject(
47            all_benchmarks, 'unusual', name_func=lambda x: x.Name()))
48