示例#1
0
 def dump(self):
     # TODO(albert): add log messages
     # TODO(albert): writing causes an error halfway, the tests
     # directory may be left in a corrupted state.
     # TODO(albert): might need to delete obsolete test files too.
     json = format.prettyjson(self.to_json())
     with open(self.file, 'w', encoding='utf-8') as f:
         f.write('test = ' + json)
示例#2
0
    def dump(self):
        # TODO(albert): add log messages
        # TODO(albert): writing causes an error halfway, the tests
        # directory may be left in a corrupted state.
        # TODO(albert): might need to delete obsolete test files too.
        json = format.prettyjson(self.to_json())
        test_tmp = "{}.tmp".format(self.file)

        with open(test_tmp, 'w', encoding='utf-8') as f:
            f.write('test = {}\n'.format(json))

        # Use an atomic rename operation to prevent test corruption
        os.replace(test_tmp, self.file)
示例#3
0
    def dump(self):
        # TODO(albert): add log messages
        # TODO(albert): writing causes an error halfway, the tests
        # directory may be left in a corrupted state.
        # TODO(albert): might need to delete obsolete test files too.
        json = format.prettyjson(self.to_json())
        test_tmp = "{}.tmp".format(self.file)

        with open(test_tmp, 'w', encoding='utf-8') as f:
            f.write('test = {}\n'.format(json))

        # Try to use os.replace, but if on Windows manually remove then rename
        # (ref issue #339)
        if os.name == 'nt':
            # TODO(colin) Add additional error handling in case process gets killed mid remove/rename
            os.remove(self.file)
            os.rename(test_tmp, self.file)
        else:
            # Use an atomic rename operation to prevent test corruption
            os.replace(test_tmp, self.file)
示例#4
0
    def dump(self):
        # TODO(albert): add log messages
        # TODO(albert): writing causes an error halfway, the tests
        # directory may be left in a corrupted state.
        # TODO(albert): might need to delete obsolete test files too.
        json = format.prettyjson(self.to_json())
        test_tmp = "{}.tmp".format(self.file)

        with open(test_tmp, 'w', encoding='utf-8') as f:
            f.write('test = {}\n'.format(json))

        # Try to use os.replace, but if on Windows manually remove then rename
        # (ref issue #339)
        if os.name == 'nt':
        # TODO(colin) Add additional error handling in case process gets killed mid remove/rename
            os.remove(self.file)
            os.rename(test_tmp, self.file)
        else:
            # Use an atomic rename operation to prevent test corruption
            os.replace(test_tmp, self.file)
示例#5
0
 def assertFormat(self, expect, json):
     self.assertEqual(format.dedent(expect), format.prettyjson(json))
示例#6
0
 def assertFormat(self, expect, json):
     self.assertEqual(format.dedent(expect), format.prettyjson(json))