Exemplo n.º 1
0
 def test_nop(self):
     """Test that creating, activating, and deleting a wrapped component doesn't fail."""
     self.component = LikeFile(DyingShunt())
     self.component.activate()
     time.sleep(
         0.25
     )  # I think this might be a threading issue - the instant shutdown is not being processed.
     self.component.shutdown()
     del self.component
Exemplo n.º 2
0
 def __init__(self, *cat_args):
     super(SolarSystem, self).__init__()
     self.the_sun = LikeFile(make_cat(*cat_args), extrainboxes = ("translation", "imaging"))
     self.the_sun.activate()
     self.planet = LikeFile(make_cat(*cat_args), extrainboxes = ("translation", "rotator", "imaging"))
     self.planet.activate()
     self.sun_position = tuple([x/2 for x in screensize])
     self.planet_position = (screensize[0]/4.0, screensize[1]/2)
     self.planet_velocity = (0.0, 10)
Exemplo n.º 3
0
 def __init__(self, *cat_args):
     super(SolarSystem, self).__init__()
     self.the_sun = LikeFile(make_cat(*cat_args),
                             extrainboxes=("translation", "imaging"))
     self.the_sun.activate()
     self.planet = LikeFile(make_cat(*cat_args),
                            extrainboxes=("translation", "rotator",
                                          "imaging"))
     self.planet.activate()
     self.sun_position = tuple([x / 2 for x in screensize])
     self.planet_position = (screensize[0] / 4.0, screensize[1] / 2)
     self.planet_velocity = (0.0, 10)
Exemplo n.º 4
0
 def test_nop(self):
     """Test that creating, activating, and deleting a wrapped component doesn't fail."""
     self.component = LikeFile(DyingShunt())
     self.component.activate()
     time.sleep(0.25) # I think this might be a threading issue - the instant shutdown is not being processed.
     self.component.shutdown()
     del self.component
Exemplo n.º 5
0
 def test_badboxuse(self):
     """test that IO on a box name that doesn't exist will fail."""
     component = LikeFile(DyingShunt())
     component.activate()
     self.failUnlessRaises(KeyError, component.put, "boo",
                           "nonsensesendbox")
     self.failUnlessRaises(KeyError, component.get, "nonsensesendbox")
     component.shutdown()
Exemplo n.º 6
0
 def test_closed(self):
     """test that creating, activating, and then closing a likefile wrapper will result in an object you're not
     allowed to perform IO on."""
     component = LikeFile(DyingShunt())
     component.activate()
     time.sleep(0.1)
     component.shutdown()
     time.sleep(0.1)
     self.failUnlessRaises(AttributeError, component.get)
     self.failUnlessRaises(AttributeError, component.put, "boo")
Exemplo n.º 7
0
class SolarSystem(Axon.ThreadedComponent.threadedcomponent):
    def __init__(self, *cat_args):
        super(SolarSystem, self).__init__()
        self.the_sun = LikeFile(make_cat(*cat_args),
                                extrainboxes=("translation", "imaging"))
        self.the_sun.activate()
        self.planet = LikeFile(make_cat(*cat_args),
                               extrainboxes=("translation", "rotator",
                                             "imaging"))
        self.planet.activate()
        self.sun_position = tuple([x / 2 for x in screensize])
        self.planet_position = (screensize[0] / 4.0, screensize[1] / 2)
        self.planet_velocity = (0.0, 10)

    # ugh, I should be using numpy but it works, that's the important thing
    # This is merely a test of likefile. Really, kamaelia components should be written for a physics simulation like this.

    def acceleration(self, pos_planet, pos_sun):
        g = 200  # fudge factor
        # F = ma, but F is proportional to distance ** -2
        # neatly removing the need to calculate a square root for the distance
        direction = (pos_planet[0] - pos_sun[0], pos_planet[1] - pos_sun[1])
        magnitude = direction[0]**2 + direction[1]**2
        return tuple([g * x / magnitude for x in direction])

    def apply_acceleration_to_velocity(self, velocity, accn):
        return (velocity[0] + accn[0], velocity[1] + accn[1])

    def apply_velocity_to_position(self, position, velocity):
        return (position[0] + velocity[0], position[1] + velocity[1])

    def main(self):
        self.the_sun.put(self.sun_position, "translation")

        while True:
            time.sleep(0.01)
            self.planet.put(self.planet_position, "translation")
            accn = self.acceleration(self.sun_position, self.planet_position)
            self.planet_velocity = self.apply_acceleration_to_velocity(
                self.planet_velocity, accn)
            self.planet_position = self.apply_velocity_to_position(
                self.planet_position, self.planet_velocity)
Exemplo n.º 8
0
class SolarSystem(Axon.ThreadedComponent.threadedcomponent):
    def __init__(self, *cat_args):
        super(SolarSystem, self).__init__()
        self.the_sun = LikeFile(make_cat(*cat_args), extrainboxes = ("translation", "imaging"))
        self.the_sun.activate()
        self.planet = LikeFile(make_cat(*cat_args), extrainboxes = ("translation", "rotator", "imaging"))
        self.planet.activate()
        self.sun_position = tuple([x/2 for x in screensize])
        self.planet_position = (screensize[0]/4.0, screensize[1]/2)
        self.planet_velocity = (0.0, 10)

    # ugh, I should be using numpy but it works, that's the important thing
    # This is merely a test of likefile. Really, kamaelia components should be written for a physics simulation like this.

    def acceleration(self, pos_planet, pos_sun):
        g = 200 # fudge factor
        # F = ma, but F is proportional to distance ** -2
        # neatly removing the need to calculate a square root for the distance
        direction = (pos_planet[0] - pos_sun[0], pos_planet[1] - pos_sun[1])
        magnitude = direction[0] ** 2 + direction[1] ** 2
        return tuple([g * x/magnitude for x in direction])

    def apply_acceleration_to_velocity(self, velocity, accn):
        return (velocity[0] + accn[0], velocity[1] + accn[1])

    def apply_velocity_to_position(self,position, velocity):
        return (position[0] + velocity[0], position[1] + velocity[1])

    def main(self):
        self.the_sun.put(self.sun_position, "translation")

        while True:
            time.sleep(0.01)
            self.planet.put(self.planet_position, "translation")
            accn = self.acceleration(self.sun_position, self.planet_position)
            self.planet_velocity = self.apply_acceleration_to_velocity(self.planet_velocity, accn)
            self.planet_position = self.apply_velocity_to_position(self.planet_position, self.planet_velocity)
Exemplo n.º 9
0
 def testmany(self):
     compdict = dict()
     for i in xrange(1, 50):  # test 100 concurrent likefiles.
         compdict[i] = LikeFile(DyingShunt(),
                                extraInboxes="extrain",
                                extraOutboxes="extraout")
         compdict[i].activate()
     time.sleep(0.1)
     for num, component in compdict.iteritems():
         for i in randlist:
             # i is a random integer between 0 and 1, so the following manipulations guarantee that each box on each
             # component gets a different number, to eliminate crosstalk passing a test.
             component.put(num + i, "inbox")
             component.put(num + i % 0.5, "control")
             component.put(num + i % 0.25, "extrain")
     for num, component in compdict.iteritems():
         for i in randlist:
             self.failUnless(component.get("outbox") == num + i)
             self.failUnless(component.get("signal") == num + i % 0.5)
             self.failUnless(component.get("extraout") == num + i % 0.25)
     for component in compdict.itervalues():
         component.shutdown()
Exemplo n.º 10
0
class test_LikeFile(unittest.TestCase):

    def status(self):
        print threading.activeCount(), len(Axon.Scheduler.scheduler.run.threads), Axon.Scheduler.scheduler.run.threads

    def setUp(self):
        self.numthreads = threading.activeCount()
        self.numcomponents = len(Axon.Scheduler.scheduler.run.threads)

    def tearDown(self):
        # the small timeout is necessary, since the shutdown signal is sent before
        # likefile has returned, and if we check immediately then it might not have died yet.
        time.sleep(0.5)
        self.failUnless(self.numcomponents == len(Axon.Scheduler.scheduler.run.threads))
        self.failUnless(self.numthreads == threading.activeCount())
        ## make sure also that creating then killing a likefile doesn't leave any crufty extra threads or extra scheduler entries.

    def test_nop(self):
        """Test that creating, activating, and deleting a wrapped component doesn't fail."""
        self.component = LikeFile(DyingShunt())
        self.component.activate()
        time.sleep(0.25) # I think this might be a threading issue - the instant shutdown is not being processed.
        self.component.shutdown()
        del self.component

    def testmany(self):
        compdict = dict()
        for i in xrange(1, 50): # test 100 concurrent likefiles.
            compdict[i] = LikeFile(DyingShunt(), extraInboxes = "extrain", extraOutboxes = "extraout")
            compdict[i].activate()
        time.sleep(0.1)
        for num, component in compdict.iteritems():
            for i in randlist:
                # i is a random integer between 0 and 1, so the following manipulations guarantee that each box on each
                # component gets a different number, to eliminate crosstalk passing a test.
                component.put(num + i, "inbox")
                component.put(num + i % 0.5, "control")
                component.put(num + i % 0.25, "extrain")
        for num, component in compdict.iteritems():
            for i in randlist:
                self.failUnless(component.get("outbox") == num + i)
                self.failUnless(component.get("signal") == num + i % 0.5)
                self.failUnless(component.get("extraout") == num + i % 0.25)
        for component in compdict.itervalues():
            component.shutdown()

    def test_aborted(self):
        """test that creating but not activating a likefile wrapper doesn't leave any cruft in the scheduler,
        and that you can't perform IO on a pre-activated component."""
        component = LikeFile(DyingShunt())
        self.failUnlessRaises(AttributeError, component.get)
        self.failUnlessRaises(AttributeError, component.put, "boo")
    def test_badboxwrap(self):
        """test that wrapping a nonexistent box will fail."""
        self.failUnlessRaises(KeyError, LikeFile, DyingShunt(), extraInboxes = "nonsenseaddbox")
        self.failUnlessRaises(KeyError, LikeFile, DyingShunt(), extraOutboxes = "nonsenseaddbox")
    def test_badboxuse(self):
        """test that IO on a box name that doesn't exist will fail."""
        component = LikeFile(DyingShunt())
        component.activate()
        self.failUnlessRaises(KeyError, component.put, "boo", "nonsensesendbox")
        self.failUnlessRaises(KeyError, component.get, "nonsensesendbox")
        component.shutdown()
    def test_closed(self):
        """test that creating, activating, and then closing a likefile wrapper will result in an object you're not
        allowed to perform IO on."""
        component = LikeFile(DyingShunt())
        component.activate()
        time.sleep(0.1)
        component.shutdown()
        time.sleep(0.1)
        self.failUnlessRaises(AttributeError, component.get)
        self.failUnlessRaises(AttributeError, component.put, "boo")
Exemplo n.º 11
0
            files.append(x)

    image_location = files[random.randint(0,len(files)-1)]

    cat_surface = pygame.image.load("pictures/"+image_location)
    cat = cat_surface.convert()
    cat.set_colorkey((255,255,255), pygame.RLEACCEL)

    newCat = CatSprite(image=cat)
    return newCat

cat_args = (cat_location, screensize, border)
spritescheduler = SpriteScheduler(cat_args, [], background, screen_surface, MyGamesEvents).activate()

newcat = make_cat(*cat_args)
the_sun = LikeFile(make_cat(*cat_args), extrainboxes = ("translation", "imaging"))
the_sun.activate()

planet = LikeFile(make_cat(*cat_args), extrainboxes = ("translation", "rotator", "imaging"))
planet.activate()
sun_position = tuple([x/2 for x in screensize])

planet_position = (screensize[0]/4.0, screensize[1]/2)
planet_velocity = (0.0, 10)


# ugh, I should be using numpy but it works, that's the important thing
# This is merely a test of likefile. Really, kamaelia components should be written for a physics simulation like this.

def acceleration(pos_planet, pos_sun):
    g = 200 # fudge factor
Exemplo n.º 12
0
 def test_aborted(self):
     """test that creating but not activating a likefile wrapper doesn't leave any cruft in the scheduler,
     and that you can't perform IO on a pre-activated component."""
     component = LikeFile(DyingShunt())
     self.failUnlessRaises(AttributeError, component.get)
     self.failUnlessRaises(AttributeError, component.put, "boo")
Exemplo n.º 13
0
class test_LikeFile(unittest.TestCase):
    def status(self):
        print threading.activeCount(), len(
            Axon.Scheduler.scheduler.run.threads
        ), Axon.Scheduler.scheduler.run.threads

    def setUp(self):
        self.numthreads = threading.activeCount()
        self.numcomponents = len(Axon.Scheduler.scheduler.run.threads)

    def tearDown(self):
        # the small timeout is necessary, since the shutdown signal is sent before
        # likefile has returned, and if we check immediately then it might not have died yet.
        time.sleep(0.5)
        self.failUnless(
            self.numcomponents == len(Axon.Scheduler.scheduler.run.threads))
        self.failUnless(self.numthreads == threading.activeCount())
        ## make sure also that creating then killing a likefile doesn't leave any crufty extra threads or extra scheduler entries.

    def test_nop(self):
        """Test that creating, activating, and deleting a wrapped component doesn't fail."""
        self.component = LikeFile(DyingShunt())
        self.component.activate()
        time.sleep(
            0.25
        )  # I think this might be a threading issue - the instant shutdown is not being processed.
        self.component.shutdown()
        del self.component

    def testmany(self):
        compdict = dict()
        for i in xrange(1, 50):  # test 100 concurrent likefiles.
            compdict[i] = LikeFile(DyingShunt(),
                                   extraInboxes="extrain",
                                   extraOutboxes="extraout")
            compdict[i].activate()
        time.sleep(0.1)
        for num, component in compdict.iteritems():
            for i in randlist:
                # i is a random integer between 0 and 1, so the following manipulations guarantee that each box on each
                # component gets a different number, to eliminate crosstalk passing a test.
                component.put(num + i, "inbox")
                component.put(num + i % 0.5, "control")
                component.put(num + i % 0.25, "extrain")
        for num, component in compdict.iteritems():
            for i in randlist:
                self.failUnless(component.get("outbox") == num + i)
                self.failUnless(component.get("signal") == num + i % 0.5)
                self.failUnless(component.get("extraout") == num + i % 0.25)
        for component in compdict.itervalues():
            component.shutdown()

    def test_aborted(self):
        """test that creating but not activating a likefile wrapper doesn't leave any cruft in the scheduler,
        and that you can't perform IO on a pre-activated component."""
        component = LikeFile(DyingShunt())
        self.failUnlessRaises(AttributeError, component.get)
        self.failUnlessRaises(AttributeError, component.put, "boo")

    def test_badboxwrap(self):
        """test that wrapping a nonexistent box will fail."""
        self.failUnlessRaises(KeyError,
                              LikeFile,
                              DyingShunt(),
                              extraInboxes="nonsenseaddbox")
        self.failUnlessRaises(KeyError,
                              LikeFile,
                              DyingShunt(),
                              extraOutboxes="nonsenseaddbox")

    def test_badboxuse(self):
        """test that IO on a box name that doesn't exist will fail."""
        component = LikeFile(DyingShunt())
        component.activate()
        self.failUnlessRaises(KeyError, component.put, "boo",
                              "nonsensesendbox")
        self.failUnlessRaises(KeyError, component.get, "nonsensesendbox")
        component.shutdown()

    def test_closed(self):
        """test that creating, activating, and then closing a likefile wrapper will result in an object you're not
        allowed to perform IO on."""
        component = LikeFile(DyingShunt())
        component.activate()
        time.sleep(0.1)
        component.shutdown()
        time.sleep(0.1)
        self.failUnlessRaises(AttributeError, component.get)
        self.failUnlessRaises(AttributeError, component.put, "boo")