def test_diff_full(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        seq1 = "zab zab2 zabc3 zabcd zabc4".split()
        seq2 = "ab ab2 abc3 abc4 abc adb".split()
        diff = SequenceMatcher(a=seq1, b=seq2)

        h = 20
        size = 500, 500
        white = 255, 255, 255

        if is_travis_or_appveyor() in ("travis",):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame, screen, fonts = get_pygame_screen_font(h, size, flags=flags)

        from ensae_teaching_cs.helpers.pygame_helper import wait_event

        bars = [random.randint(10, 500) / 500.0 for s in seq2]
        screen.fill(white)
        build_diff_image(pygame, screen, h=h, maxw=size[1], seq1=seq1, seq2=seq2, diff=diff,
                         fonts=fonts, bars=bars)
        pygame.display.flip()
        temp = get_temp_folder(__file__, "temp_video_diff_full")

        for i in range(0, 21):
            screen.fill(white)
            build_diff_image(pygame, screen, h=h, maxw=size[0], seq1=seq1, seq2=seq2, diff=diff,
                             fonts=fonts, bars=bars, progress=i / 20.0, prev_bars=None)
            pygame.time.wait(60)
            pygame.display.flip()
            pygame.image.save(screen, os.path.join(temp, "diff%d.png" % i))

        if __name__ == "__main__":

            from ensae_teaching_cs.helpers.video_helper import make_video
            png = [os.path.join(temp, _)
                   for _ in os.listdir(temp) if ".png" in _]
            out = os.path.join(temp, "diff.avi")
            make_video(png, out, size=(350, 250), format="XVID", fps=5)

            wait_event(pygame)

        for font in fonts.values():
            del font
        pygame.quit()
    def test_image_video_puzzle_girafe(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_image_video_girafe")

        if is_travis_or_appveyor() in ("travis",):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame_simulation(pygame, fLOG=fLOG, folder=temp,
                          delay=200 if __name__ == "__main__" else 2,
                          flags=flags)
        files = os.listdir(temp)
        assert len(files) > 9
        png = [os.path.join(temp, _)
               for _ in files if os.path.splitext(_)[-1] == ".png"]
        assert len(png) > 0
        out = os.path.join(temp, "puzzle_girafe.avi")
        v = make_video(png, out, size=(500, 500), format="XVID", fps=4)
        assert v is not None
    def test_image_video_epidemic(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_image_video_epidemic")

        if is_travis_or_appveyor() in ("travis",):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame_simulation(pygame, fLOG=fLOG, iter=10, folder=temp, flags=flags)
        files = os.listdir(temp)
        self.assertTrue(len(files) > 9)
        png = [os.path.join(temp, _)
               for _ in files if os.path.splitext(_)[-1] == ".png"]
        self.assertTrue(len(png) > 0)
        out = os.path.join(temp, "epidemic.avi")

        v = make_video(png, out, size=(300, 300), format="XVID")
        self.assertTrue(v is not None)
    def test_image_video_epidemic(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_image_video_voisinage")

        if is_travis_or_appveyor() in ("travis", ):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame_simulation(pygame,
                          fLOG=fLOG,
                          folder=temp,
                          max_iter=150 if __name__ == "__main__" else 10,
                          flags=flags)
        files = os.listdir(temp)
        assert len(files) > 9
        png = [
            os.path.join(temp, _) for _ in files
            if os.path.splitext(_)[-1] == ".png"
        ]
        assert len(png) > 0
        out = os.path.join(temp, "voisinage.avi")
        v = make_video(png, out, size=(500, 500), format="XVID")
        assert v is not None
Exemplo n.º 5
0
    def test_kruskal_pygame_simulation(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        temp = get_temp_folder(__file__, "temp_kruskal_pygame_simulation")

        if is_travis_or_appveyor() in ("travis", ):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame.init()

        pygame_simulation(fLOG=fLOG,
                          max_iter=10 if __name__ != "__main__" else 10000,
                          pygame=pygame,
                          folder=temp,
                          flags=flags)

        files = os.listdir(temp)
        self.assertGreater(len(files), 9)
        png = [
            os.path.join(temp, _) for _ in files
            if os.path.splitext(_)[-1] == ".png"
        ]
        self.assertGreater(len(png), 0)
        out = os.path.join(temp, "tsp_kruskal.avi")
        v = make_video(png, out, size=(800, 500), format="XVID", fps=20)
        self.assertNotEmpty(v)
Exemplo n.º 6
0
    def test_image_video_pendule(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_image_video_pendule")

        if is_travis_or_appveyor() in ("travis", ):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame_simulation(pygame,
                          fLOG=fLOG,
                          iter=4000 if __name__ == "__main__" else 100,
                          folder=temp,
                          flags=flags,
                          model="pendule")
        files = os.listdir(temp)
        self.assertTrue(len(files) > 9)
        png = [
            os.path.join(temp, _) for _ in files
            if os.path.splitext(_)[-1] == ".png"
        ]
        self.assertTrue(len(png) > 0)
        out = os.path.join(temp, "pendule.avi")

        v = make_video(png, out, size=(400, 300), format="XVID", fps=24)
        self.assertTrue(v is not None)
    def test_kruskal_pygame_simulation(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        temp = get_temp_folder(__file__, "temp_kruskal_pygame_simulation")

        if is_travis_or_appveyor() in ("travis",):
            # pygame.error: No available video device
            return
        import pygame
        if is_travis_or_appveyor() == "circleci":
            # os.environ["SDL_VIDEODRIVER"] = "x11"
            flags = pygame.NOFRAME
        else:
            flags = 0

        pygame.init()

        pygame_simulation(fLOG=fLOG, max_iter=10 if __name__ != "__main__" else 10000,
                          pygame=pygame, folder=temp, flags=flags)

        files = os.listdir(temp)
        self.assertGreater(len(files), 9)
        png = [os.path.join(temp, _)
               for _ in files if os.path.splitext(_)[-1] == ".png"]
        self.assertGreater(len(png), 0)
        out = os.path.join(temp, "tsp_kruskal.avi")
        v = make_video(png, out, size=(800, 500), format="XVID", fps=20)
        self.assertNotEmpty(v)
    def test_make_video(self):
        """
        This test does not work under a virtual environment.
        """
        temp = get_temp_folder(__file__, "temp_make_video")
        img = os.path.join(temp, "..", "data")
        imgs = os.listdir(img)
        png = [os.path.join(img, _)
               for _ in imgs if os.path.splitext(_)[-1] == ".png" and "00" in _]
        self.assertGreater(len(png), 0)
        out = os.path.join(temp, "out_video.avi")

        v = make_video(png, out, size=(1000, 300))
        self.assertExists(out)
        self.assertGreater(os.stat(out).st_size, 90000)
        self.assertNotEmpty(v)