2 # Copyright (c) 2013 The Chromium 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.
9 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
10 BUILD_TOOLS_DIR
= os
.path
.dirname(SCRIPT_DIR
)
12 sys
.path
.append(BUILD_TOOLS_DIR
)
14 import sdk_tools
.config
as config
16 class TestSdkToolsConfig(unittest
.TestCase
):
17 def testInvalidSyntax(self
):
18 invalid_json
= "# oops\n"
20 self
.assertRaises(config
.Error
, lambda: cfg
.LoadJson(invalid_json
))
22 def testEmptyConfig(self
):
23 """Test that empty config contains just empty sources list."""
24 expected
= '{\n "sources": []\n}'
26 json_output
= cfg
.ToJson()
27 self
.assertEqual(json_output
, expected
)
29 def testIntegerSetting(self
):
30 json_input
= '{ "setting": 3 }'
32 cfg
.LoadJson(json_input
)
33 self
.assertEqual(cfg
.setting
, 3)
35 def testReadWrite(self
):
36 json_input1
= '{\n "sources": [], \n "setting": 3\n}'
37 json_input2
= '{\n "setting": 3\n}'
38 for json_input
in (json_input1
, json_input2
):
40 cfg
.LoadJson(json_input
)
41 json_output
= cfg
.ToJson()
42 self
.assertEqual(json_output
, json_input1
)
44 def testAddSource(self
):
46 cfg
.AddSource('http://localhost/foo')
47 json_output
= cfg
.ToJson()
48 expected
= '{\n "sources": [\n "http://localhost/foo"\n ]\n}'
49 self
.assertEqual(json_output
, expected
)
52 if __name__
== '__main__':