Example #1
0
 def test_decompress(self):
     for key in self.FILES:
         output_path = gf.tmp_directory()
         f = self.FILES[key]
         cont = Container(f["path"])
         cont.decompress(output_path)
         copy = Container(output_path, ContainerFormat.UNPACKED)
         self.assertEqual(copy.entries, self.EXPECTED_ENTRIES)
         gf.delete_directory(output_path)
Example #2
0
 def test_decompress(self):
     for key in self.FILES:
         output_path = gf.tmp_directory()
         f = self.FILES[key]
         cont = Container(f["path"])
         cont.decompress(output_path)
         copy = Container(output_path, ContainerFormat.UNPACKED)
         self.assertEqual(copy.entries, self.EXPECTED_ENTRIES)
         gf.delete_directory(output_path)
Example #3
0
 def test_compress_unpacked(self):
     input_path = self.FILES["unpacked"]["path"]
     output_path = gf.tmp_directory()
     cont = Container(output_path, ContainerFormat.UNPACKED)
     cont.compress(input_path)
     self.assertFalse(os.path.isfile(output_path))
     copy = Container(output_path, ContainerFormat.UNPACKED)
     self.assertEqual(copy.entries, self.EXPECTED_ENTRIES)
     gf.delete_directory(output_path)
Example #4
0
 def test_compress_unpacked(self):
     input_path = self.FILES["unpacked"]["path"]
     output_path = gf.tmp_directory()
     cont = Container(output_path, ContainerFormat.UNPACKED)
     cont.compress(input_path)
     self.assertFalse(os.path.isfile(output_path))
     copy = Container(output_path, ContainerFormat.UNPACKED)
     self.assertEqual(copy.entries, self.EXPECTED_ENTRIES)
     gf.delete_directory(output_path)
Example #5
0
 def test_copytree(self):
     orig = gf.tmp_directory()
     tmp_path = os.path.join(orig, "foo.bar")
     with io.open(tmp_path, "w", encoding="utf-8") as tmp_file:
         tmp_file.write(u"Foo bar")
     dest = gf.tmp_directory()
     gf.copytree(orig, dest)
     self.assertTrue(gf.file_exists(os.path.join(dest, "foo.bar")))
     gf.delete_directory(dest)
     gf.delete_directory(orig)
Example #6
0
 def test_exec_tmp_path(self):
     tmp_path = gf.tmp_directory()
     self.execute([
         ("in", "../tools/res/audio.mp3"),
         ("in", "../tools/res/subtitles.txt"),
         ("", "task_language=eng|is_text_type=subtitles|os_task_file_format=srt"),
         ("out", "sonnet.srt"),
         ("", "-r=\"tmp_path=%s\"" % tmp_path)
     ], 0)
     gf.delete_directory(tmp_path)
 def test_copytree(self):
     orig = gf.tmp_directory()
     tmp_path = os.path.join(orig, "foo.bar")
     with io.open(tmp_path, "w", encoding="utf-8") as tmp_file:
         tmp_file.write(u"Foo bar")
     dest = gf.tmp_directory()
     gf.copytree(orig, dest)
     self.assertTrue(gf.file_exists(os.path.join(dest, "foo.bar")))
     gf.delete_directory(dest)
     gf.delete_directory(orig)
Example #8
0
 def execute(self, path):
     input_path = gf.absolute_path(path, __file__)
     output_path = gf.tmp_directory()
     executor = ExecuteJob(job=None)
     executor.load_job_from_container(input_path)
     self.assertIsNotNone(executor.job)
     executor.execute()
     result_path = executor.write_output_container(output_path)
     self.assertIsNotNone(result_path)
     self.assertTrue(gf.file_exists(result_path))
     executor.clean()
     gf.delete_directory(output_path)
Example #9
0
 def execute(self, path):
     input_path = gf.absolute_path(path, __file__)
     output_path = gf.tmp_directory()
     executor = ExecuteJob(job=None)
     executor.load_job_from_container(input_path)
     self.assertIsNotNone(executor.job)
     executor.execute()
     result_path = executor.write_output_container(output_path)
     self.assertIsNotNone(result_path)
     self.assertTrue(gf.file_exists(result_path))
     executor.clean()
     gf.delete_directory(output_path)
 def execute(self, parameters, expected_exit_code):
     output_path = gf.tmp_directory()
     params = ["placeholder"]
     for p_type, p_value in parameters:
         if p_type == "in":
             params.append(gf.absolute_path(p_value, __file__))
         elif p_type == "out":
             params.append(os.path.join(output_path, p_value))
         else:
             params.append(p_value)
     exit_code = ExecuteJobCLI(use_sys=False).run(arguments=params)
     gf.delete_directory(output_path)
     self.assertEqual(exit_code, expected_exit_code)
 def execute(self, parameters, expected_exit_code):
     output_path = gf.tmp_directory()
     params = ["placeholder"]
     for p_type, p_value in parameters:
         if p_type == "in":
             params.append(gf.absolute_path(p_value, __file__))
         elif p_type == "out":
             params.append(os.path.join(output_path, p_value))
         else:
             params.append(p_value)
     exit_code = ExecuteJobCLI(use_sys=False).run(arguments=params)
     gf.delete_directory(output_path)
     self.assertEqual(exit_code, expected_exit_code)
Example #12
0
 def test_ensure_parent_directory(self):
     orig = gf.tmp_directory()
     tmp_path = os.path.join(orig, "foo.bar")
     tmp_parent = orig
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "foo/bar.baz")
     tmp_parent = os.path.join(orig, "foo")
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "bar")
     gf.ensure_parent_directory(tmp_path, ensure_parent=False)
     self.assertTrue(gf.directory_exists(tmp_path))
     gf.delete_directory(orig)
 def test_ensure_parent_directory(self):
     orig = gf.tmp_directory()
     tmp_path = os.path.join(orig, "foo.bar")
     tmp_parent = orig
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "foo/bar.baz")
     tmp_parent = os.path.join(orig, "foo")
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "bar")
     gf.ensure_parent_directory(tmp_path, ensure_parent=False)
     self.assertTrue(gf.directory_exists(tmp_path))
     gf.delete_directory(orig)
Example #14
0
 def convert(self, input_file_path, ofp=None, runtime_configuration=None):
     if ofp is None:
         output_path = gf.tmp_directory()
         output_file_path = os.path.join(output_path, "audio.wav")
     else:
         output_file_path = ofp
     try:
         converter = FFMPEGWrapper(rconf=runtime_configuration)
         result = converter.convert(
             gf.absolute_path(input_file_path, __file__), output_file_path)
         self.assertEqual(result, output_file_path)
         gf.delete_directory(output_path)
     except OSError as exc:
         if ofp is None:
             gf.delete_directory(output_path)
         else:
             gf.delete_file(None, ofp)
         raise exc
Example #15
0
    def clean(self, remove_working_directory=True):
        """
        Remove the temporary directory.
        If ``remove_working_directory`` is ``True``
        remove the working directory as well,
        otherwise just remove the temporary directory.

        :param bool remove_working_directory: if ``True``, remove
                                              the working directory as well
        """
        if remove_working_directory is not None:
            self.log(u"Removing working directory... ")
            gf.delete_directory(self.working_directory)
            self.working_directory = None
            self.log(u"Removing working directory... done")
        self.log(u"Removing temporary directory... ")
        gf.delete_directory(self.tmp_directory)
        self.tmp_directory = None
        self.log(u"Removing temporary directory... done")
Example #16
0
    def clean(self, remove_working_directory=True):
        """
        Remove the temporary directory.
        If ``remove_working_directory`` is ``True``
        remove the working directory as well,
        otherwise just remove the temporary directory.

        :param bool remove_working_directory: if ``True``, remove
                                              the working directory as well
        """
        if remove_working_directory is not None:
            self.log(u"Removing working directory... ")
            gf.delete_directory(self.working_directory)
            self.working_directory = None
            self.log(u"Removing working directory... done")
        self.log(u"Removing temporary directory... ")
        gf.delete_directory(self.tmp_directory)
        self.tmp_directory = None
        self.log(u"Removing temporary directory... done")
Example #17
0
 def convert(self, input_file_path, ofp=None, runtime_configuration=None):
     if ofp is None:
         output_path = gf.tmp_directory()
         output_file_path = os.path.join(output_path, "audio.wav")
     else:
         output_file_path = ofp
     try:
         converter = FFMPEGWrapper(rconf=runtime_configuration)
         result = converter.convert(
             gf.absolute_path(input_file_path, __file__),
             output_file_path
         )
         self.assertEqual(result, output_file_path)
         gf.delete_directory(output_path)
     except OSError as exc:
         if ofp is None:
             gf.delete_directory(output_path)
         else:
             gf.delete_file(None, ofp)
         raise exc
 def test_delete_directory_existing(self):
     orig = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
 def test_delete_directory_not_existing(self):
     orig = "/foo/bar/baz"
     self.assertFalse(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Example #20
0
 def test_find_entry_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertIsNone(cont.find_entry(self.EXPECTED_ENTRIES[0]))
     gf.delete_directory(output_path)
Example #21
0
 def test_is_safe_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertTrue(cont.is_safe)
     gf.delete_directory(output_path)
Example #22
0
 def test_entries_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertEqual(len(cont.entries), 0)
     gf.delete_directory(output_path)
Example #23
0
 def test_exists_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertTrue(cont.exists())
     gf.delete_directory(output_path)
Example #24
0
 def test_tmp_directory(self):
     tmp_dir = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(tmp_dir))
     gf.delete_directory(tmp_dir)
Example #25
0
 def test_delete_directory_existing(self):
     orig = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Example #26
0
 def test_delete_directory_not_existing(self):
     orig = "/foo/bar/baz"
     self.assertFalse(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Example #27
0
 def test_find_entry_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertIsNone(cont.find_entry(self.EXPECTED_ENTRIES[0]))
     gf.delete_directory(output_path)
 def test_tmp_directory(self):
     tmp_dir = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(tmp_dir))
     gf.delete_directory(tmp_dir)
Example #29
0
 def test_exists_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertTrue(cont.exists())
     gf.delete_directory(output_path)
Example #30
0
 def test_is_safe_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertTrue(cont.is_safe)
     gf.delete_directory(output_path)
Example #31
0
 def test_entries_empty_directory(self):
     output_path = gf.tmp_directory()
     cont = Container(output_path)
     self.assertEqual(len(cont.entries), 0)
     gf.delete_directory(output_path)