Example #1
0
 def test_write_file(self):
     data = ['a', 'b', 'c']
     # TODO: Do tempfile.mkstemp stuff
     tempfilepath = tempfile.mktemp()
     transform = utils.write_file(tempfilepath)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         self.assertEqual(temp_f.read(), 'a\nb\nc\n')
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)
Example #2
0
 def test_write_file(self):
     data = ['a', 'b', 'c']
     # TODO: Do tempfile.mkstemp stuff
     tempfilepath = tempfile.mktemp()
     transform = utils.write_file(tempfilepath)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         self.assertEqual(temp_f.read(), 'a\nb\nc\n')
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)
Example #3
0
 def test_write_file_append(self):
     data = ['a', 'b', 'c']
     tempfilepath = tempfile.mktemp()
     with open(tempfilepath, 'w') as temp_f:
         temp_f.write('zzz\n')
     transform = utils.write_file(tempfilepath, append=True)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         self.assertEqual(temp_f.read(), 'zzz\na\nb\nc\n')
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)
Example #4
0
 def test_write_file_append(self):
     data = ['a', 'b', 'c']
     tempfilepath = tempfile.mktemp()
     with open(tempfilepath, 'w') as temp_f:
         temp_f.write('zzz\n')
     transform = utils.write_file(tempfilepath, append=True)
     result = list(transform(data))
     self.assertEqual(result, data)
     with open(tempfilepath, 'r') as temp_f:
         self.assertEqual(temp_f.read(), 'zzz\na\nb\nc\n')
     # FIXME This probably doesn't remove the file if the assertion fails.
     os.remove(tempfilepath)