2 # Copyright 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.
7 from copy
import deepcopy
9 from schema_processor
import SchemaProcessor
10 from future
import Future
11 from object_store_creator
import ObjectStoreCreator
12 from host_file_system_provider
import HostFileSystemProvider
13 from compiled_file_system
import CompiledFileSystem
15 class _FakeReferenceResolver():
16 def GetRefModel(self
, ref
, api_list
):
19 class _FakeAPIModels():
23 class _FakeFeaturesBundle():
24 def GetAPIFeatures(self
):
25 return Future(value
={})
27 class SchemaUtilTest(unittest
.TestCase
):
28 def testRemoveNoDocs(self
):
123 object_store_creator
= ObjectStoreCreator(start_empty
=False)
124 host_file_system_provider
= HostFileSystemProvider(object_store_creator
)
125 schema_processor
= SchemaProcessor(_FakeReferenceResolver(),
127 _FakeFeaturesBundle(),
128 CompiledFileSystem
.Factory(
129 object_store_creator
),
130 host_file_system_provider
.GetMaster(),
132 schema_processor
._RemoveNoDocs
(nodoc_data
)
133 self
.assertEquals(expected_nodoc
, nodoc_data
)
135 def testInlineDocs(self
):
137 'namespace': 'storage',
140 'description': 'second key',
144 'description': 'first key',
152 'id': 'Key', # Should be inlined into both properties and be removed
154 'description': 'This is a key.', # This description should disappear.
155 'marker': True # This should appear three times in the output.
163 'description': 'A list of keys'
169 'namespace': 'storage',
174 'description': 'second key'
179 'description': 'first key'
190 'description': 'A list of keys'
195 object_store_creator
= ObjectStoreCreator(start_empty
=False)
196 host_file_system_provider
= HostFileSystemProvider(object_store_creator
)
197 schema_processor
= SchemaProcessor(_FakeReferenceResolver(),
199 _FakeFeaturesBundle(),
200 CompiledFileSystem
.Factory(
201 object_store_creator
),
202 host_file_system_provider
.GetMaster(),
204 inlined_schema
= deepcopy(schema
)
205 schema_processor
._InlineDocs
(inlined_schema
)
206 self
.assertEqual(expected_schema
, inlined_schema
)
208 def testDetectInline(self
):
235 object_store_creator
= ObjectStoreCreator(start_empty
=False)
236 host_file_system_provider
= HostFileSystemProvider(object_store_creator
)
237 schema_processor
= SchemaProcessor(_FakeReferenceResolver(),
239 _FakeFeaturesBundle(),
240 CompiledFileSystem
.Factory(
241 object_store_creator
),
242 host_file_system_provider
.GetMaster(),
244 schema_processor
._DetectInlineableTypes
(schema
)
245 schema_processor
._InlineDocs
(schema
)
246 self
.assertEqual(expected_schema
, schema
)
249 if __name__
== '__main__':