Example #1
0
 def simple(self):
     # simple test without cleanup:
     assert len(self._polygon) > 3 
     gallery = ArtGallery(self._polygon.pop(self.main_index))
     for point in self._polygon:
         gallery.include(point)
             
     self.preview_control.show(gallery, title = "Without cleanup")
Example #2
0
class TestProcess(threading.Thread):
    '''
    Generate a mono and mult thread test for Art Gallery Previewer
    '''
    STARTING = 1
    RUNNING = 2
    STOPPING = 3
    
    num_threads = 0
    lock = threading.Lock()
    _big_delay = 0.25
    
    def __init__(self, points, index_main_point, delay):
        with TestProcess.lock:
            self.id = TestProcess.num_threads
            TestProcess.num_threads += 1
            self._polygon = points[:]
            ArtGalleryPainter.set_polygon(self._polygon)
            self.gallery = ArtGallery(self._polygon.pop(index_main_point))
        self.delay = delay
        self.big_delay = TestProcess._big_delay \
                         if delay < TestProcess._big_delay \
                         else delay
        self.state = TestProcess.STARTING
        threading.Thread.__init__(self)
        self.counter = 0
        

    def start(self):
        threading.Thread.start(self)

    def stop(self):
        self.state = TestProcess.STOPPING
        
    def must_exit(self):
        self.counter += 1
        threading.Event().wait(self.delay)
        return self.state != TestProcess.RUNNING

    def must_exit_delay(self, delay):
        self.counter += 1
        threading.Event().wait(delay)
        return self.state != TestProcess.RUNNING

    def run(self):
        self.state = TestProcess.RUNNING
        while True:
            size = len(self._polygon)
            if size == 0 or self.must_exit(): break
            index = random.randint(0, size - 1)
            point = self._polygon.pop(index)
            self.gallery.include(point)
        # keep running until receive a stop sign
        while self.state == TestProcess.RUNNING:
            pass