コード例 #1
0
ファイル: models.py プロジェクト: jackzhao-mj/ok-client
 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
ファイル: models.py プロジェクト: shamhub/python_programming
    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
ファイル: format_test.py プロジェクト: yuvipanda/ok-client
 def assertFormat(self, expect, json):
     self.assertEqual(format.dedent(expect), format.prettyjson(json))
コード例 #6
0
ファイル: format_test.py プロジェクト: jackzhao-mj/ok-client
 def assertFormat(self, expect, json):
     self.assertEqual(format.dedent(expect), format.prettyjson(json))