Beispiel #1
0
    def test_remove_unpickables_lock(self):
        a = SimpleClass()
        a.l = threading.Lock()

        mapper.remove_unpickables(a)

        self.assertEquals(None, a.l)
    def test_remove_unpickables_lock(self):
        a = SimpleClass()
        a.l = threading.Lock()

        mapper.remove_unpickables(a)

        self.assertEquals(None, a.l)
 def test_remove_unpickables_datetime(self):
     sc = SimpleClass()
     sc.time = datetime.datetime(2007, 12, 31, 23, 55)
     mapper.remove_unpickables(sc)
     self.assertEquals(2007, sc.time.year)
     self.assertEquals(12  , sc.time.month)
     self.assertEquals(31  , sc.time.day)
     self.assertEquals(23  , sc.time.hour)
     self.assertEquals(55  , sc.time.minute)
Beispiel #4
0
 def test_remove_unpickables_datetime(self):
     sc = SimpleClass()
     sc.time = datetime.datetime(2007, 12, 31, 23, 55)
     mapper.remove_unpickables(sc)
     self.assertEquals(2007, sc.time.year)
     self.assertEquals(12, sc.time.month)
     self.assertEquals(31, sc.time.day)
     self.assertEquals(23, sc.time.hour)
     self.assertEquals(55, sc.time.minute)
Beispiel #5
0
    def test_remove_unpickables_ignorable(self):
        parser = expat_parser.ParserCreate()
        self.assertRaises(pickle.PicklingError, pickle.dumps, parser)

        my_class = MyClass2()
        my_class.parser = parser

        mapper.remove_unpickables(my_class)

        pickle.dumps(my_class)  # No problem now
        self.assertEqual(None, my_class.parser)
    def test_remove_unpickables_ignorable(self):
        parser = expat_parser.ParserCreate()
        self.assertRaises(
                    pickle.PicklingError,
                    pickle.dumps,
                    parser
            )

        my_class = MyClass2()
        my_class.parser = parser

        mapper.remove_unpickables(my_class)

        pickle.dumps(my_class) # No problem now
        self.assertEqual(None, my_class.parser)
    def test_remove_unpickables_http_exception(self):
        try:
            urllib2.urlopen("http://localhost/this.does.not.exist")
            self.fail("exception expected")
        except urllib2.URLError as e:
            pass
        except urllib2.HTTPError as e:
            pass

        removed = mapper.remove_unpickables(e)
        pickled = pickle.dumps(removed)
        pickle.loads(pickled)
Beispiel #8
0
    def test_remove_unpickables_http_exception(self):
        try:
            urllib2.urlopen("http://localhost/this.does.not.exist")
            self.fail("exception expected")
        except urllib2.URLError as e:
            pass
        except urllib2.HTTPError as e:
            pass

        removed = mapper.remove_unpickables(e)
        pickled = pickle.dumps(removed)
        pickle.loads(pickled)
Beispiel #9
0
    def start(self):
        # Launching trials...
        print("New trial. %i iterations" % self.iterations)
        self.bot_trial = self._launch_trial()

        print("Cleaning results...", time.asctime())
        self.bot_trial = mapper.remove_unpickables(self.bot_trial)

        if self.pickle_file_name is not None:
            try:
                print("Storing results...", time.asctime())
                self._dump_results()
                print("Results stored", time.asctime())
            except Exception as e:
                print("Error: Couldn't store results into %s: %r" % (self.pickle_file_name, e))
Beispiel #10
0
    def start(self):
        # Launching trials...
        print("New trial. %i iterations" % self.iterations)
        self.bot_trial = self._launch_trial()

        print("Cleaning results...", time.asctime())
        self.bot_trial = mapper.remove_unpickables(self.bot_trial)

        if self.pickle_file_name is not None:
            try:
                print("Storing results...", time.asctime())
                self._dump_results()
                print("Results stored",time.asctime())
            except Exception as e:
                print("Error: Couldn't store results into %s: %r" % (self.pickle_file_name, e))
Beispiel #11
0
    def test_remove_unpickables_general(self):
        mc = MyClass(1, 2, (1, 2))
        mc.and_another = MyClass(1, 3, (1, 3))

        moc = MyOtherClass(4 + 4j)

        # Cyclic references
        jac1 = JetAnotherClass(None)
        jac2 = JetAnotherClass(jac1)
        jac1.otherReference = jac2

        # mc and moc can't be pickled
        # pickle raises pickle.PicklingError in Python < 2.7 but TypeError in Python 2.7; we try both exceptions
        try:
            self.assertRaises(pickle.PicklingError, pickle.dumps, mc)
        except:
            failed_first_time = True
        else:
            failed_first_time = False

        try:
            self.assertRaises(TypeError, pickle.dumps, mc)
        except:
            if failed_first_time:
                raise

        self.assertRaises(TypeError, pickle.dumps, moc)

        mapper.remove_unpickables(mc)

        self.assertEquals(1, mc._first_field)
        self.assertEquals(2, mc._second_field)
        self.assertEquals((1, 2), mc._third_field)
        self.assertEquals(1 + 2, mc.sum_of_fields)
        self.assertEquals(  #Lock not allowed
            None, mc.another)
        self.assertEquals(5.5, mc.yet_another)
        # And inside and_another... so on
        self.assertEquals(1, mc.and_another._first_field)

        # What about moc?
        mapper.remove_unpickables(moc)
        self.assertEquals(4 + 4j, moc.param)
        self.assertEquals(None, moc.param2)

        # What about JetAnotherClass?
        mapper.remove_unpickables(jac1)

        # Go ahead! Pickle me! ;-D
        pickled = pickle.dumps(mc)
        pickle.loads(pickled)

        pickled = pickle.dumps(moc)
        pickle.loads(pickled)
Beispiel #12
0
    def test_remove_unpickables_general(self):
        mc = MyClass(1,2,(1,2))
        mc.and_another = MyClass(1,3,(1,3))

        moc = MyOtherClass(4+4j)

        # Cyclic references
        jac1 = JetAnotherClass(None)
        jac2 = JetAnotherClass(jac1)
        jac1.otherReference = jac2

        # mc and moc can't be pickled
        # pickle raises pickle.PicklingError in Python < 2.7 but TypeError in Python 2.7; we try both exceptions
        try:
            self.assertRaises(
                pickle.PicklingError,
                pickle.dumps,
                mc
            )
        except:
            failed_first_time = True
        else:
            failed_first_time = False

        try:
            self.assertRaises(
                TypeError,
                pickle.dumps,
                mc
            )
        except:
            if failed_first_time:
               raise


        self.assertRaises(
                TypeError,
                pickle.dumps,
                moc
            )

        mapper.remove_unpickables(mc)

        self.assertEquals(
                1,
                mc._first_field
            )
        self.assertEquals(
                2,
                mc._second_field
            )
        self.assertEquals(
                (1,2),
                mc._third_field
            )
        self.assertEquals(
                1 + 2,
                mc.sum_of_fields
            )
        self.assertEquals( #Lock not allowed
                None,
                mc.another
            )
        self.assertEquals(
                5.5,
                mc.yet_another
            )
        # And inside and_another... so on
        self.assertEquals(
                1,
                mc.and_another._first_field
            )

        # What about moc?
        mapper.remove_unpickables(moc)
        self.assertEquals(
                4+4j,
                moc.param
            )
        self.assertEquals(
                None,
                moc.param2
            )

        # What about JetAnotherClass?
        mapper.remove_unpickables(jac1)

        # Go ahead! Pickle me! ;-D
        pickled      = pickle.dumps(mc)
        pickle.loads(pickled)

        pickled      = pickle.dumps(moc)
        pickle.loads(pickled)
Beispiel #13
0
 def test_remove_unpickables_not_comparable_instances(self):
     dt = xmlrpclib.DateTime()
     # DateTime throws exception when doing:
     #   dt == {}
     # for instance
     mapper.remove_unpickables({"foo" : dt})
Beispiel #14
0
 def test_remove_unpickables_not_comparable_instances(self):
     dt = xmlrpclib.DateTime()
     # DateTime throws exception when doing:
     #   dt == {}
     # for instance
     mapper.remove_unpickables({"foo": dt})