コード例 #1
0
ファイル: utils_test.py プロジェクト: jagill/python-chainz
 def test_write_jsonl_file(self):
     # TODO: Do tempfile stuff
     data = [
         {'a': 1, 'b': False},
         {'c': 'd', 'b': False},
     ]
     tempfilepath = tempfile.mktemp()
     transform = utils.write_jsonl_file(tempfilepath)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         result_data = [json.loads(x) for x in temp_f]
         self.assertEqual(result_data, data)
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)
コード例 #2
0
ファイル: utils_test.py プロジェクト: jagill/python-chainz
 def test_write_jsonl_file_append(self):
     data = [
         {'a': 1, 'b': False},
         {'c': 'd', 'b': False},
     ]
     extra = {'d': 'e', 'b': True}
     expected_data = [extra] + data
     tempfilepath = tempfile.mktemp()
     with open(tempfilepath, 'w') as temp_f:
         temp_f.write(json.dumps(extra) + '\n')
     transform = utils.write_jsonl_file(tempfilepath, append=True)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         result_data = [json.loads(x) for x in temp_f]
         self.assertEqual(result_data, expected_data)
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)
コード例 #3
0
 def test_write_jsonl_file(self):
     # TODO: Do tempfile stuff
     data = [
         {
             'a': 1,
             'b': False
         },
         {
             'c': 'd',
             'b': False
         },
     ]
     tempfilepath = tempfile.mktemp()
     transform = utils.write_jsonl_file(tempfilepath)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         result_data = [json.loads(x) for x in temp_f]
         self.assertEqual(result_data, data)
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)
コード例 #4
0
 def test_write_jsonl_file_append(self):
     data = [
         {
             'a': 1,
             'b': False
         },
         {
             'c': 'd',
             'b': False
         },
     ]
     extra = {'d': 'e', 'b': True}
     expected_data = [extra] + data
     tempfilepath = tempfile.mktemp()
     with open(tempfilepath, 'w') as temp_f:
         temp_f.write(json.dumps(extra) + '\n')
     transform = utils.write_jsonl_file(tempfilepath, append=True)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         result_data = [json.loads(x) for x in temp_f]
         self.assertEqual(result_data, expected_data)
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)