Beispiel #1
0
 def test_extra_broken_database(self):
     """Verify that the platform database falls back to the built in database
     even when it can't write to disk
     """
     with patch("mbed_os_tools.detect.platform_database.open") as _open:
         _open.side_effect = IOError("Bogus")
         self.pdb = PlatformDatabase([LOCAL_PLATFORM_DATABASE])
         self.pdb.add("1234", "MYTARGET")
         self.assertEqual(self.pdb.get("1234"), "MYTARGET")
Beispiel #2
0
 def test_broken_database_io(self):
     """Verify that the platform database still works without a
     working backing file
     """
     with patch("mbed_os_tools.detect.platform_database.open") as _open:
         _open.side_effect = IOError("Bogus")
         self.pdb = PlatformDatabase([self.base_db_path])
         self.pdb.add("1234", "MYTARGET")
         self.assertEqual(self.pdb.get("1234"), "MYTARGET")
Beispiel #3
0
 def test_broken_database_bad_json(self):
     """Verify that the platform database still works without a
     working backing file
     """
     self.base_db.write(b'{}')
     self.base_db.seek(0)
     self.pdb = PlatformDatabase([self.base_db_path])
     self.pdb.add("1234", "MYTARGET")
     self.assertEqual(self.pdb.get("1234"), "MYTARGET")
Beispiel #4
0
 def test_old_database(self):
     """Verify that the platform database correctly updates's its database
     """
     with patch("mbed_lstools.platform_database.open") as _open,\
          patch("mbed_lstools.platform_database.getmtime") as _getmtime:
         stringio = MagicMock()
         _open.return_value = stringio
         _getmtime.side_effect = (0, 1000000)
         self.pdb = PlatformDatabase([LOCAL_PLATFORM_DATABASE])
         stringio.__enter__.return_value.write.assert_called_with(
             unicode(json.dumps(DEFAULT_PLATFORM_DB)))
Beispiel #5
0
    def setUp(self):
        self.mocked_lock = patch('mbed_lstools.platform_database.InterProcessLock', spec=True).start()
        self.acquire = self.mocked_lock.return_value.acquire
        self.release = self.mocked_lock.return_value.release

        self.base_db_path = os.path.join(tempfile.mkdtemp(), 'base')
        self.base_db = open(self.base_db_path, 'w+b')
        self.base_db.write(b'{}')
        self.base_db.seek(0)
        self.pdb = PlatformDatabase([self.base_db_path])
        self.addCleanup(patch.stopall)
Beispiel #6
0
 def test_broken_database(self):
     """Verify that the platform database correctly reset's its database
     """
     with patch("mbed_lstools.platform_database.open") as _open:
         stringio = MagicMock()
         _open.side_effect = (IOError("Bogus"), stringio)
         self.pdb = PlatformDatabase([LOCAL_PLATFORM_DATABASE])
         stringio.__enter__.return_value.write.assert_called_with(
             unicode(json.dumps(DEFAULT_PLATFORM_DB)))
         self.pdb.add("1234", "MYTARGET")
         self.assertEqual(self.pdb.get("1234"), "MYTARGET")
Beispiel #7
0
 def setUp(self):
     self.mocked_lock = patch(
         'mbed_lstools.platform_database.InterProcessLock',
         spec=True).start()
     self.acquire = self.mocked_lock.return_value.acquire
     self.release = self.mocked_lock.return_value.release
     self.base_db = tempfile.NamedTemporaryFile(prefix='base')
     self.base_db.write(b'{}')
     self.base_db.seek(0)
     self.pdb = PlatformDatabase([self.base_db.name])
     self.addCleanup(patch.stopall)
Beispiel #8
0
 def setUp(self):
     self.base_db = tempfile.NamedTemporaryFile(prefix='base')
     self.base_db.write(
         json.dumps(dict([('0123', 'Base_Platform')])).encode('utf-8'))
     self.base_db.seek(0)
     self.overriding_db = tempfile.NamedTemporaryFile(prefix='overriding')
     self.overriding_db.write(b'{}')
     self.overriding_db.seek(0)
     self.pdb = PlatformDatabase(
         [self.overriding_db.name, self.base_db.name],
         primary_database=self.overriding_db.name)
     self.base_db.seek(0)
     self.overriding_db.seek(0)
Beispiel #9
0
 def test_load_override(self):
     """Check that adding a platform goes to the Override database and
     you can no longer query for the base database definition and
     that the override database was not written to disk
     """
     self.overriding_db.write(json.dumps(dict([('0123', 'Overriding_Platform')])).
                              encode('utf-8'))
     self.overriding_db.seek(0)
     self.pdb = PlatformDatabase([self.overriding_db_path, self.base_db_path],
                                 primary_database=self.overriding_db_path)
     self.assertIn(('0123', 'Overriding_Platform'), list(self.pdb.items()))
     self.assertEqual(set(self.pdb.all_ids()), set(['0123']))
     self.assertEqual(self.pdb.get('0123'), 'Overriding_Platform')
     self.assertBaseUnchanged()
Beispiel #10
0
 def setUp(self):
     self.temp_dir = tempfile.mkdtemp()
     self.base_db_path = os.path.join(self.temp_dir, 'base')
     self.base_db = open(self.base_db_path, 'w+b')
     self.base_db.write(json.dumps(dict([('0123', 'Base_Platform')])).
                        encode('utf-8'))
     self.base_db.seek(0)
     self.overriding_db_path = os.path.join(self.temp_dir, 'overriding')
     self.overriding_db = open(self.overriding_db_path, 'w+b')
     self.overriding_db.write(b'{}')
     self.overriding_db.seek(0)
     self.pdb = PlatformDatabase([self.overriding_db_path, self.base_db_path],
                                 primary_database=self.overriding_db_path)
     self.base_db.seek(0)
     self.overriding_db.seek(0)
Beispiel #11
0
 def setUp(self):
     self.base_db_path = os.path.join(tempfile.mkdtemp(), 'base')
     self.base_db = open(self.base_db_path, 'w+b')
     self.base_db.write(b'{}')
     self.base_db.seek(0)
     self.pdb = PlatformDatabase([self.base_db_path])
Beispiel #12
0
 def setUp(self):
     self.base_db = tempfile.NamedTemporaryFile(prefix='base')
     self.base_db.write(b'{}')
     self.base_db.seek(0)
     self.pdb = PlatformDatabase([self.base_db.name])