def test_string_to_file_path_ok(self): """ Check if string_to_file_path creates a file with proper contents. """ file_path = ansible.string_to_file_path("TEST ąęłźżó") try: with open(file_path, 'r') as f: self.assertEqual("TEST ąęłźżó", f.read()) finally: os.remove(file_path)
def test_string_to_file_path(self): """ Store a string in a temporary file """ test_str = 'My kewl string\nwith unicode «ταБЬℓσ», now 20% off!' file_path_copy = None with ansible.string_to_file_path(test_str) as file_path: with open(file_path) as fp: self.assertEqual(fp.read(), test_str) file_path_copy = file_path self.assertTrue(os.path.isfile(file_path_copy)) self.assertFalse(os.path.isfile(file_path_copy))