Пример #1
0
    def test_pathological(self):
        # just make sure this never errors, since it's meant to be used
        # during deletion
        a = A()
        a.__dict__ = BadKeysDict()

        a.fruit = 'mango'
        with self.assertRaises(RuntimeError):
            a.__dict__.keys()

        strip_attrs(a)
        # no error, but the attribute is still there
        self.assertEqual(a.fruit, 'mango')

        a = A()
        a.__dict__ = NoDelDict()
        s = 'can\'t touch this!'
        a.x = s

        self.assertEqual(a.x, s)
        # not sure how this doesn't raise, but it doesn't.
        # with self.assertRaises(KeyError):
        #     del a.x

        strip_attrs(a)
        self.assertEqual(a.x, s)
Пример #2
0
    def test_normal(self):
        a = A()
        a.x = 15
        a.z = 25

        strip_attrs(a)

        self.assertEqual(a.x, 5)
        self.assertFalse(hasattr(a, 'z'))
        self.assertEqual(a.y, 6)
Пример #3
0
    def close(self):
        """Irreversibly stop this instrument and free its resources.
        Closes the serial connection too"""
        if hasattr(self, 'connection') and hasattr(self.connection, 'close'):
            self.connection.close()
        ser = self._ser
        ser.close()

        strip_attrs(self, whitelist=['name'])
        self.remove_instance(self)
Пример #4
0
def test_normal():
    a = A()
    a.x = 15
    a.z = 25

    strip_attrs(a)

    assert a.x == 5
    assert not hasattr(a, 'z')
    assert a.y == 6
Пример #5
0
    def close(self):
        """
        Irreversibly stop this instrument and free its resources.

        Subclasses should override this if they have other specific
        resources to close.
        """
        if hasattr(self, 'connection') and hasattr(self.connection, 'close'):
            self.connection.close()

        strip_attrs(self, whitelist=['name'])
        self.remove_instance(self)
Пример #6
0
    def close(self):
        """Disconnect and irreversibly tear down the instrument."""

        # VisaInstrument close
        if getattr(self, 'visa_handle', None):
            self.visa_handle.close()

        # Instrument close
        if hasattr(self, 'connection') and hasattr(self.connection, 'close'):
            self.connection.close()

        strip_attrs(self, whitelist=['name'])
        self.remove_instance(self)
Пример #7
0
    def close(self) -> None:
        """
        Irreversibly stop this instrument and free its resources.

        Subclasses should override this if they have other specific
        resources to close.
        """
        if hasattr(self, 'connection') and hasattr(self.connection, 'close'):
            self.connection.close()

        # check for the existense first since this may already
        # have been striped e.g. if the instrument has been closed once before
        if hasattr(self, "instrument_modules"):
            for module in self.instrument_modules.values():
                strip_attrs(module, whitelist=["_short_name", "_parent"])

        if hasattr(self, "_channel_lists"):
            for channellist in self._channel_lists.values():
                for channel in channellist:
                    strip_attrs(channel, whitelist=["_short_name", "_parent"])

        strip_attrs(self, whitelist=["_short_name"])
        self.remove_instance(self)