Flutter Engine
The Flutter Engine
database_test.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5"""Tests for database module."""
6
7import logging.config
8import os.path
9import shutil
10import tempfile
11import unittest
12import database
13import idlnode
14import idlparser
15
16
17class DatabaseTestCase(unittest.TestCase):
18
19 def _ParseInterface(self, content):
20 ast = self._idl_parser.parse(content)
21 return idlnode.IDLFile(ast).interfaces[0]
22
23 def _ListInterfaces(self, db):
24 res = []
25 for interface in db.GetInterfaces():
26 name = interface.id
27 res.append(name)
28 return res
29
30 def setUp(self):
31 self._idl_parser = idlparser.IDLParser(idlparser.FREMONTCUT_SYNTAX)
32
33 working_dir = tempfile.mkdtemp()
34 self._database_dir = os.path.join(working_dir, 'database')
35 self.assertFalse(os.path.exists(self._database_dir))
36
37 # Create database and add one interface.
39 interface = self._ParseInterface('interface I1 {};')
40 db.AddInterface(interface)
41 db.Save()
42 self.assertTrue(
43 os.path.exists(os.path.join(self._database_dir, 'I1.idl')))
44
45 def tearDown(self):
46 shutil.rmtree(self._database_dir)
47
48 def testCreate(self):
49 self.assertTrue(os.path.exists(self._database_dir))
50
53 db.Load()
54 self.assertEqual(self._ListInterfaces(db), ['I1'])
55
58 db.Load()
59 self.assertTrue(db.HasInterface('I1'))
60 self.assertFalse(db.HasInterface('I2'))
61
64 db.Load()
65 interface = self._ParseInterface('interface I2 {};')
66 db.AddInterface(interface)
67 db.Save()
68 self.assertTrue(
69 os.path.exists(os.path.join(self._database_dir, 'I2.idl')))
70 self.assertEqual(self._ListInterfaces(db), ['I1', 'I2'])
71
74 db.Load()
75 db.DeleteInterface('I1')
76 db.Save()
77 self.assertFalse(
78 os.path.exists(os.path.join(self._database_dir, 'I1.idl')))
79 self.assertEqual(self._ListInterfaces(db), [])
80
83 db.Load()
84 interface = db.GetInterface('I1')
85 self.assertEqual(interface.id, 'I1')
86
87
88if __name__ == '__main__':
89 logging.config.fileConfig('logging.conf')
90 if __name__ == '__main__':
91 unittest.main()
def parse(repo_root, recipes_cfg_path)
Definition: recipes.py:56