Example #1
0
 def check_contents(self, file_path, contents):
     """Compare `contents` with the contents of the file at `file_path`.
     Asserts equality.
     """
     mode = 'rb' if is_byte_string(contents) else 'r'
     with self.open(file_path, mode) as f:
         self.assertEqual(contents, f.read())
Example #2
0
 def check_contents(self, file_path, contents):
     """Compare `contents` with the contents of the file at `file_path`.
     Asserts equality.
     """
     mode = 'rb' if is_byte_string(contents) else 'r'
     with self.open(file_path, mode) as f:
         self.assertEqual(contents, f.read())
Example #3
0
    def create_file(self, file_path, contents=None, encoding=None):
        """Create the given file at `file_path` with optional contents, including
        subdirectories. `file_path` shall be composed using `make_path()`.
        """
        self.create_dir(self.os.path.dirname(file_path))
        mode = 'wb' if encoding is not None or is_byte_string(
            contents) else 'w'

        if encoding is not None and contents is not None:
            contents = contents.encode(encoding)
        with self.open(file_path, mode) as f:
            if contents is not None:
                f.write(contents)
        self.os.chmod(file_path, 0o666)
Example #4
0
    def create_file(self, file_path, contents=None, encoding=None):
        """Create the given file at `file_path` with optional contents,
        including subdirectories. `file_path` shall be composed using
        `make_path()`.
        """
        self.create_dir(self.os.path.dirname(file_path))
        mode = ('wb' if encoding is not None or is_byte_string(contents)
                else 'w')

        if encoding is not None and contents is not None:
            contents = contents.encode(encoding)
        with self.open(file_path, mode) as f:
            if contents is not None:
                f.write(contents)
        self.os.chmod(file_path, 0o666)