• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2# Copyright (c) 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from __future__ import print_function
7from __future__ import unicode_literals
8import unittest
9import common
10from autotest_lib.site_utils import stable_version_classify as sv
11
12
13class StableVersionClassifyModelBoard(unittest.TestCase):
14    """test that classify board and classify model report the
15    correct information source based on the config values"""
16    def test_empty_config(self):
17        fc = _FakeConfig(enable=False, boards=[], models=[])
18        self.assertEqual(
19            sv.classify_board('xxx-board', _config_override=fc),
20            sv.FROM_AFE,
21        )
22        self.assertEqual(
23            sv.classify_model('xxx-model', _config_override=fc),
24            sv.FROM_AFE
25        )
26
27    def test_empty_config_but_enabled(self):
28        fc = _FakeConfig(enable=True, boards=[], models=[])
29        self.assertEqual(
30            sv.classify_board('xxx-board', _config_override=fc),
31            sv.FROM_AFE,
32        )
33        self.assertEqual(
34            sv.classify_model('xxx-model', _config_override=fc),
35            sv.FROM_AFE
36        )
37
38    def test_just_nocturne_config(self):
39        fc = _FakeConfig(enable=True, boards=[u'nocturne'], models=[u'nocturne'])
40        self.assertEqual(
41            sv.classify_board('xxx-board', _config_override=fc),
42            sv.FROM_AFE,
43        )
44        self.assertEqual(
45            sv.classify_model('xxx-model', _config_override=fc),
46            sv.FROM_AFE,
47        )
48        self.assertEqual(
49            sv.classify_board('nocturne', _config_override=fc),
50            sv.FROM_HOST_CONFIG,
51        )
52        self.assertEqual(
53            sv.classify_model('nocturne', _config_override=fc),
54            sv.FROM_HOST_CONFIG,
55        )
56
57
58    def test_enable_all(self):
59        fc = _FakeConfig(enable=True, boards=[u':all'], models=[u':all'])
60        self.assertEqual(
61            sv.classify_board('xxx-board', _config_override=fc),
62            sv.FROM_HOST_CONFIG,
63        )
64        self.assertEqual(
65            sv.classify_model('xxx-model', _config_override=fc),
66            sv.FROM_HOST_CONFIG,
67        )
68        self.assertEqual(
69            sv.classify_board('nocturne', _config_override=fc),
70            sv.FROM_HOST_CONFIG,
71        )
72        self.assertEqual(
73            sv.classify_model('nocturne', _config_override=fc),
74            sv.FROM_HOST_CONFIG,
75        )
76
77
78_TEXT = (type(u''), type(b''))
79
80
81class _FakeConfig(object):
82    def __init__(self, boards=None, models=None, enable=None):
83        assert isinstance(boards, list)
84        assert isinstance(models, list)
85        assert isinstance(enable, bool)
86        self.boards = boards
87        self.models = models
88        self.enable = enable
89
90    def get_config_value(self, namespace, key, type=None, default=None):
91        assert isinstance(namespace, _TEXT)
92        assert isinstance(key, _TEXT)
93        assert namespace == 'CROS'
94        if key == 'stable_version_config_repo_enable':
95            return self.enable
96        if key == 'stable_version_config_repo_opt_in_boards':
97            return self.boards
98        if key == 'stable_version_config_repo_opt_in_models':
99            return self.models
100        assert False, "unrecognized key %s" % key
101
102
103
104if __name__ == '__main__':
105    unittest.main()
106