def test_normal_setstate(self):
        """ Validates that only existing setstate methods are called when
            there are no registered state functions in the class chain.
        """
        # Validate that unpickling the first class gives us an instance of
        # the third class with the appropriate attribute values.  It will have
        # the default Foo values (because there is no state function to move
        # them) and also the default Baz values (since they inherit the
        # trait defaults because nothing overwrote the values.)
        start = Foo()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 1, (False, 1, 1, 'foo'))
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (False, 3, 3, 'baz'))

        # Validate that unpickling the second class gives us an instance of
        # the third class with the appropriate attribute values.  It will have
        # only the Baz attributes with the Bar values (since the __setstate__
        # on Baz converted the Bar attributes to Baz attributes.)
        start = Bar()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (True, 2, 2, 'bar'))
    def test_normal_setstate(self):
        """ Validates that only existing setstate methods are called when
            there are no registered state functions in the class chain.
        """
        # Validate that unpickling the first class gives us an instance of
        # the third class with the appropriate attribute values.  It will have
        # the default Foo values (because there is no state function to move
        # them) and also the default Baz values (since they inherit the
        # trait defaults because nothing overwrote the values.)
        start = Foo()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 1, (False, 1, 1, 'foo'))
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (False, 3, 3, 'baz'))

        # Validate that unpickling the second class gives us an instance of
        # the third class with the appropriate attribute values.  It will have
        # only the Baz attributes with the Bar values (since the __setstate__
        # on Baz converted the Bar attributes to Baz attributes.)
        start = Bar()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (True, 2, 2, 'bar'))
示例#3
0
    def test_unpickled_class_mapping(self):

        # Add the mappings to the registry
        self.registry.add_mapping_to_class(Foo.__module__, Foo.__name__, Bar)
        self.registry.add_mapping_to_class(Bar.__module__, Bar.__name__, Baz)

        # Validate that unpickling the first class gives us an instance of
        # the third class.
        start = Foo()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))

        # Validate that unpickling the second class gives us an instance of
        # the third class.
        start = Bar()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
    def test_unpickled_class_mapping(self):

        # Add the mappings to the registry
        self.registry.add_mapping_to_class(Foo.__module__, Foo.__name__,
            Bar)
        self.registry.add_mapping_to_class(Bar.__module__, Bar.__name__,
            Baz)

        # Validate that unpickling the first class gives us an instance of
        # the third class.
        start = Foo()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))

        # Validate that unpickling the second class gives us an instance of
        # the third class.
        start = Bar()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
    def test_unpickled_chain_functionality(self):
        """ Validates that the registered state functions are used when
            unpickling.
        """
        # Add the state function to the registry
        self.registry.add_state_function_for_class(Bar, 2, bar_state_function)

        # Validate that unpickling the first class gives us an instance of
        # the third class with the appropriate attribute values.
        start = Foo()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 1, None)
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (False, 1, 1, 'foo'))

        # Validate that unpickling the second class gives us an instance of
        # the third class.
        start = Bar()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (True, 2, 2, 'bar'))
    def test_unpickled_chain_functionality(self):
        """ Validates that the registered state functions are used when
            unpickling.
        """
        # Add the state function to the registry
        self.registry.add_state_function_for_class(Bar, 2,
            bar_state_function)

        # Validate that unpickling the first class gives us an instance of
        # the third class with the appropriate attribute values.
        start = Foo()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 1, None)
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (False, 1, 1, 'foo'))

        # Validate that unpickling the second class gives us an instance of
        # the third class.
        start = Bar()
        end = sweet_pickle.loads(sweet_pickle.dumps(start))
        self.assertEqual(True, isinstance(end, Baz))
        self._assertAttributes(end, 2, None)
        self._assertAttributes(end, 3, (True, 2, 2, 'bar'))
示例#7
0
    def _execute_pattern(self, pat):
        self.info('executing pattern {}'.format(pat))

        if not pat.endswith('.lp'):
            pat = '{}.lp'.format(pat)

        path = os.path.join(paths.pattern_dir, pat)
        if os.path.isfile(path):
            self.debug('Using local pattern {}'.format(pat))
            pat = pickle.dumps(path)
            self.debug('Sending Pattern:{}'.format(pat))

        cmd = 'DoPattern {}'.format(pat)
        self._ask(cmd, verbose=False)

        time.sleep(0.5)

        if not self._block('IsPatterning', period=1):
            cmd = 'AbortPattern'
            self._ask(cmd)
示例#8
0
    def _execute_pattern(self, pat):
        self.info('executing pattern {}'.format(pat))

        if not pat.endswith('.lp'):
            pat = '{}.lp'.format(pat)

        path = os.path.join(paths.pattern_dir, pat)
        if os.path.isfile(path):
            self.debug('Using local pattern {}'.format(pat))
            pat = pickle.dumps(path)
            self.debug('Sending Pattern:{}'.format(pat))

        cmd = 'DoPattern {}'.format(pat)
        self._ask(cmd, verbose=False)

        time.sleep(0.5)

        if not self._block('IsPatterning', period=1):
            cmd = 'AbortPattern'
            self._ask(cmd)
示例#9
0
 def fn(o):
     sweet_pickle.loads(sweet_pickle.dumps(o))
 def fn(o):
     sweet_pickle.loads(sweet_pickle.dumps(o))