Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: lib/dom/scripts/database_test.py

Issue 10913125: Remove lib/dom directory! (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
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
6 """Tests for database module."""
7
8 import logging.config
9 import os.path
10 import shutil
11 import tempfile
12 import unittest
13 import database
14 import idlnode
15 import idlparser
16
17
18 class DatabaseTestCase(unittest.TestCase):
19
20 def _ParseInterface(self, content):
21 ast = self._idl_parser.parse(content)
22 return idlnode.IDLFile(ast).interfaces[0]
23
24 def _ListInterfaces(self, db):
25 res = []
26 for interface in db.GetInterfaces():
27 name = interface.id
28 res.append(name)
29 return res
30
31 def setUp(self):
32 self._idl_parser = idlparser.IDLParser(idlparser.FREMONTCUT_SYNTAX)
33
34 working_dir = tempfile.mkdtemp()
35 self._database_dir = os.path.join(working_dir, 'database')
36 self.assertFalse(os.path.exists(self._database_dir))
37
38 # Create database and add one interface.
39 db = database.Database(self._database_dir)
40 interface = self._ParseInterface('interface I1 {};')
41 db.AddInterface(interface)
42 db.Save()
43 self.assertTrue(
44 os.path.exists(os.path.join(self._database_dir, 'I1.idl')))
45
46 def tearDown(self):
47 shutil.rmtree(self._database_dir)
48
49 def testCreate(self):
50 self.assertTrue(os.path.exists(self._database_dir))
51
52 def testListInterfaces(self):
53 db = database.Database(self._database_dir)
54 db.Load()
55 self.assertEquals(self._ListInterfaces(db), ['I1'])
56
57 def testHasInterface(self):
58 db = database.Database(self._database_dir)
59 db.Load()
60 self.assertTrue(db.HasInterface('I1'))
61 self.assertFalse(db.HasInterface('I2'))
62
63 def testAddInterface(self):
64 db = database.Database(self._database_dir)
65 db.Load()
66 interface = self._ParseInterface('interface I2 {};')
67 db.AddInterface(interface)
68 db.Save()
69 self.assertTrue(
70 os.path.exists(os.path.join(self._database_dir, 'I2.idl')))
71 self.assertEquals(self._ListInterfaces(db),
72 ['I1', 'I2'])
73
74 def testDeleteInterface(self):
75 db = database.Database(self._database_dir)
76 db.Load()
77 db.DeleteInterface('I1')
78 db.Save()
79 self.assertFalse(
80 os.path.exists(os.path.join(self._database_dir, 'I1.idl')))
81 self.assertEquals(self._ListInterfaces(db), [])
82
83 def testGetInterface(self):
84 db = database.Database(self._database_dir)
85 db.Load()
86 interface = db.GetInterface('I1')
87 self.assertEquals(interface.id, 'I1')
88
89
90 if __name__ == '__main__':
91 logging.config.fileConfig('logging.conf')
92 if __name__ == '__main__':
93 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698