예제 #1
0
    def test_file(self):
        """Test :class:`.File` methods."""
        cwd = os.getcwd()
        testfiles_dir = os.path.join(cwd, 'tests/type_test_files')
        testfile_path = os.path.join(testfiles_dir, 'image.gif')
        file = File(testfile_path, testfiles_dir)

        self.assertIsInstance(file, File, "Instantiated 'File' class object")

        # Check arguments are stored properly
        self.assertEquals(file.base_dir, testfiles_dir,
                          "Check base_dir() method")
        self.assertEquals(file.filepath, testfile_path,
                          "Check filepath() method")

        self.assertEquals(file.name, 'image.gif', "Check name() method")
        self.assertEquals(file.dir, testfiles_dir, "Check dir() method")

        self.assertEquals(file.public_dir, '', "Check public_dir() method")
        self.assertEquals(file.public_filepath, "image.gif",
                          "Check public_filepath() method")

        self.assertEquals(file.type, 'image', "Check type() method")
        self.assertEquals(file.type_string, 'Image (gif/jpg etc)',
                          "Check type_string() method")

        # TODO implement sha256sum function
        self.assertEquals(file.sha256sum, "NOT IMPLEMENTED YET",
                          "Check sha256sum method()")
        self.assertEquals(file.checksum, "8KwlZuQvByH23-4HIcANGQ==",
                          "Generate checksum (MD5)")
        file.description = 'This is my favorite photo.'
        self.assertEquals(file.description, 'This is my favorite photo.',
                          "Check description() method")
        self.assertEquals(file.is_tex_type, False,
                          "Check is_tex_type() method")
        self.assertEquals(file.ext, '.gif', "Check ext() method is '.gif'")
        self.assertEquals(file.size, 495, "Check size of '.gif' is 495")
        mtime = os.path.getmtime(file.filepath)
        modified_datetime = datetime.datetime.fromtimestamp(
            mtime, tz=UTC).isoformat()
        self.assertEquals(file.modified_datetime, modified_datetime,
                          "Check modification time of file.")
예제 #2
0
    def test_file_setters(self):
        """Test that we are able to set various settings."""
        cwd = os.getcwd()
        testfiles_dir = os.path.join(cwd, 'tests')
        testfile_path = os.path.join(testfiles_dir,
                                     'type_test_files/polch.tex')
        file = File(testfile_path, testfiles_dir)

        # Check arguments are stored properly
        self.assertEquals(file.base_dir, testfiles_dir,
                          "Check base_dir() method")
        self.assertEquals(file.filepath, testfile_path,
                          "Check filepath() method")

        # new base dir
        new_dir = os.path.join(testfiles_dir, 'type_test_files')
        file.base_dir = new_dir
        self.assertEquals(file.base_dir, new_dir, "Check base_dir() method")

        file.description = "test setter"
        self.assertEquals(file.description, 'test setter',
                          "Check description() method")