aboutsummaryrefslogtreecommitdiff
path: root/tests/mobly/config_parser_test.py
blob: 46548f0f2758bbafbe0b61b2bcf21ccf455cdbe1 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import io
import os
import shutil
import tempfile
import unittest

from mobly import config_parser


class OutputTest(unittest.TestCase):
  """This test class has unit tests for the implementation of Mobly's output
  files.
  """

  def setUp(self):
    self.tmp_dir = tempfile.mkdtemp()

  def tearDown(self):
    shutil.rmtree(self.tmp_dir)

  def test__load_config_file(self):
    tmp_file_path = os.path.join(self.tmp_dir, 'config.yml')
    with io.open(tmp_file_path, 'w', encoding='utf-8') as f:
      f.write('TestBeds:\n')
      f.write('  # A test bed where adb will find Android devices.\n')
      f.write('  - Name: SampleTestBed\n')
      f.write('    Controllers:\n')
      f.write("        AndroidDevice: '*'\n")

    config = config_parser._load_config_file(tmp_file_path)
    self.assertEqual(config['TestBeds'][0]['Name'], 'SampleTestBed')

  def test__load_config_file_with_unicode(self):
    tmp_file_path = os.path.join(self.tmp_dir, 'config.yml')
    with io.open(tmp_file_path, 'w', encoding='utf-8') as f:
      f.write('TestBeds:\n')
      f.write('  # A test bed where adb will find Android devices.\n')
      f.write('  - Name: \u901a\n')
      f.write('    Controllers:\n')
      f.write("        AndroidDevice: '*'\n")

    config = config_parser._load_config_file(tmp_file_path)
    self.assertEqual(config['TestBeds'][0]['Name'], '\u901a')

  def test_run_config_type(self):
    config = config_parser.TestRunConfig()
    self.assertNotIn('summary_writer', str(config))
    self.assertNotIn('register_controller', str(config))

  def test_run_config_controller_configs_is_already_initialized(self):
    config = config_parser.TestRunConfig()
    expected_value = 'SOME_VALUE'
    self.assertEqual(
        config.controller_configs.get('NON_EXISTENT_KEY', expected_value),
        expected_value,
    )

  def test_run_config_user_params_is_already_initialized(self):
    config = config_parser.TestRunConfig()
    expected_value = 'SOME_VALUE'
    self.assertEqual(
        config.user_params.get('NON_EXISTENT_KEY', expected_value),
        expected_value,
    )


if __name__ == '__main__':
  unittest.main()