コード例 #1
0
    def test_insert_images_does_not_insert_non_images(self):
        with deepstar_path():
            tmpdir = os.environ['DEEPSTAR_PATH'] + '/test'

            os.mkdir(tmpdir)

            with open(os.path.join(tmpdir, 'test'), 'w') as file_:
                file_.write('test')

            with open(os.path.join(tmpdir, 'test.txt'), 'w') as file_:
                file_.write('test')

            args = ['main.py', 'insert', 'frame_sets', 'images', tmpdir]
            opts = {}

            route_handler = FrameSetCommandLineRouteHandler()

            try:
                sys.stdout = StringIO()
                route_handler.handle(args, opts)
                actual = sys.stdout.getvalue().strip()
            finally:
                sys.stdout = sys.__stdout__

            # stdout
            self.assertEqual(actual, 'frame_set_id=1, fk_videos=None')

            # db
            result = FrameSetModel().select(1)
            self.assertEqual(result, (1, None))
            result = FrameModel().list(0)
コード例 #2
0
    def test_list(self):
        with deepstar_path():
            video_model = VideoModel()
            video_model.insert('test1', 'test2')
            video_model.insert('test3', 'test4')
            video_model.insert('test5', 'test6')

            frame_set_model = FrameSetModel()
            frame_set_model.insert(1)
            frame_set_model.insert(2)
            frame_set_model.insert(3)

            args = ['main.py', 'list', 'frame_sets']
            opts = {}

            route_handler = FrameSetCommandLineRouteHandler()

            try:
                sys.stdout = StringIO()
                route_handler.handle(args, opts)
                actual = sys.stdout.getvalue().strip()
            finally:
                sys.stdout = sys.__stdout__

            # stdout
            expected = textwrap.dedent('''
            3 results
            id | fk_videos
            -------------
            1 | 1
            2 | 2
            3 | 3''').strip()

            self.assertEqual(actual, expected)
コード例 #3
0
    def test_usage(self):
        with deepstar_path():
            route_handler = FrameSetCommandLineRouteHandler()

            args = ['main.py', 'usage', 'frame_sets']
            opts = {}

            try:
                sys.stdout = StringIO()
                route_handler.handle(args, opts)
                actual = sys.stdout.getvalue().strip()
            finally:
                sys.stdout = sys.__stdout__

            self.assertTrue('Usage - Frame Sets' in actual)
コード例 #4
0
    def test_insert_images(self):
        with deepstar_path():
            image_0001 = os.path.dirname(os.path.realpath(__file__)) + '/../../support/image_0001.jpg'  # noqa
            image_0007 = os.path.dirname(os.path.realpath(__file__)) + '/../../support/image_0007.png'  # noqa

            tmpdir = os.environ['DEEPSTAR_PATH'] + '/test'

            os.mkdir(tmpdir)

            shutil.copy(image_0001, os.path.join(tmpdir, 'image_0001.jpg'))
            shutil.copy(image_0001, os.path.join(tmpdir, 'image_0002.jpg'))
            shutil.copy(image_0007, os.path.join(tmpdir, 'image_0003.png'))
            shutil.copy(image_0007, os.path.join(tmpdir, 'image_0004.png'))

            args = ['main.py', 'insert', 'frame_sets', 'images', tmpdir]
            opts = {}

            route_handler = FrameSetCommandLineRouteHandler()

            try:
                sys.stdout = StringIO()
                route_handler.handle(args, opts)
                actual = sys.stdout.getvalue().strip()
            finally:
                sys.stdout = sys.__stdout__

            # stdout
            self.assertEqual(actual, 'frame_set_id=1, fk_videos=None')

            # db
            result = FrameSetModel().select(1)
            self.assertEqual(result, (1, None))
            result = FrameModel().list(1)
            self.assertEqual(len(result), 4)
            self.assertEqual(result[0], (1, 1, 0))
            self.assertEqual(result[1], (2, 1, 0))
            self.assertEqual(result[2], (3, 1, 0))
            self.assertEqual(result[3], (4, 1, 0))

            # files
            p1 = FrameSetSubDir.path(1)

            # frames
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 1, 'jpg')))
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 2, 'jpg')))
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 3, 'jpg')))
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 4, 'jpg')))