Files
sdk/tools/dom/scripts/database_test.py
T
Nate Bosch 55f81f2210 Mass format python with yapf
- Add `.style.yapf` with configuration to use Google style.
- Run `yapf` on all `.py` files in this repo.
- Manually fix one trailing space in a doc string.
- Run `git cl format runtime` to satisfy presubmit.

Change-Id: I7e6bd11e91f07926b9188362599af398551eed79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111600
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2019-08-05 20:34:31 +00:00

92 lines
2.8 KiB
Python
Executable File

#!/usr/bin/python
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
"""Tests for database module."""
import logging.config
import os.path
import shutil
import tempfile
import unittest
import database
import idlnode
import idlparser
class DatabaseTestCase(unittest.TestCase):
def _ParseInterface(self, content):
ast = self._idl_parser.parse(content)
return idlnode.IDLFile(ast).interfaces[0]
def _ListInterfaces(self, db):
res = []
for interface in db.GetInterfaces():
name = interface.id
res.append(name)
return res
def setUp(self):
self._idl_parser = idlparser.IDLParser(idlparser.FREMONTCUT_SYNTAX)
working_dir = tempfile.mkdtemp()
self._database_dir = os.path.join(working_dir, 'database')
self.assertFalse(os.path.exists(self._database_dir))
# Create database and add one interface.
db = database.Database(self._database_dir)
interface = self._ParseInterface('interface I1 {};')
db.AddInterface(interface)
db.Save()
self.assertTrue(
os.path.exists(os.path.join(self._database_dir, 'I1.idl')))
def tearDown(self):
shutil.rmtree(self._database_dir)
def testCreate(self):
self.assertTrue(os.path.exists(self._database_dir))
def testListInterfaces(self):
db = database.Database(self._database_dir)
db.Load()
self.assertEquals(self._ListInterfaces(db), ['I1'])
def testHasInterface(self):
db = database.Database(self._database_dir)
db.Load()
self.assertTrue(db.HasInterface('I1'))
self.assertFalse(db.HasInterface('I2'))
def testAddInterface(self):
db = database.Database(self._database_dir)
db.Load()
interface = self._ParseInterface('interface I2 {};')
db.AddInterface(interface)
db.Save()
self.assertTrue(
os.path.exists(os.path.join(self._database_dir, 'I2.idl')))
self.assertEquals(self._ListInterfaces(db), ['I1', 'I2'])
def testDeleteInterface(self):
db = database.Database(self._database_dir)
db.Load()
db.DeleteInterface('I1')
db.Save()
self.assertFalse(
os.path.exists(os.path.join(self._database_dir, 'I1.idl')))
self.assertEquals(self._ListInterfaces(db), [])
def testGetInterface(self):
db = database.Database(self._database_dir)
db.Load()
interface = db.GetInterface('I1')
self.assertEquals(interface.id, 'I1')
if __name__ == '__main__':
logging.config.fileConfig('logging.conf')
if __name__ == '__main__':
unittest.main()