def test_write_dictionary_one_to_set_empty_path_works(self):
     file_name = TestCase.id(self) + '_friends.txt'
     self.assertFalse(os.path.exists(file_name),
                      msg='The file should not exist as precondition')
     write_dictionary_one_to_set(self.friends, '', file_name)
     self.assertTrue(os.path.exists(file_name),
                     msg='The file was not created')
     os.remove(file_name)
 def test_write_dictionary_one_to_set_non_existent_path_creates_file(self):
     file_name = TestCase.id(self) + '_friends.txt'
     file_path = 'a/path/'
     self.assertFalse(os.path.exists(file_path + file_name),
                      msg='The file should not exist as precondition')
     write_dictionary_one_to_set(self.friends, file_path, file_name)
     self.assertTrue(os.path.exists(file_path + file_name),
                     msg='The file was not created')
     os.remove(file_path + file_name)
     os.rmdir('a/path/')
     os.rmdir('a/')
    def test_write_dictionary_one_to_set_all_keys(self):
        file_name = TestCase.id(self) + '_friends.txt'
        self.assertFalse(os.path.exists(file_name),
                         msg='The file should not exist as precondition')
        write_dictionary_one_to_set(self.friends, '', file_name)

        with open(file_name) as file:
            lines = file.readlines()
            self.assertIn('David\tEster\n', lines, msg='Missing entry line')
            self.assertIn('Michael\tDavid\n', lines, msg='Missing entry line')
            self.assertIn('James\tMartha\n', lines, msg='Missing entry line')
        os.remove(file_name)
    def test_write_dictionary_one_to_set_one_row_each_set_entry(self):
        """Having a key with multiple values, writes one row for each key -- value pair"""
        file_name = TestCase.id(self) + '_friends.txt'
        self.assertFalse(os.path.exists(file_name),
                         msg='The file should not exist as precondition')
        write_dictionary_one_to_set(self.friends, '', file_name)

        with open(file_name) as file:
            lines = file.readlines()
            self.assertEqual(6,
                             len(lines),
                             msg='Wrong number of lines in the file')
            self.assertIn('David\tEster\n', lines, msg='Missing entry line')
            self.assertIn('David\tMartha\n', lines, msg='Missing entry line')
            self.assertIn('David\tMathew\n', lines, msg='Missing entry line')
        os.remove(file_name)
 def test_write_dictionary_one_to_set_empty_file_name_raises_error(self):
     with self.assertRaises(ValueError,
                            msg="Should not accept empty file name"):
         write_dictionary_one_to_set({}, '', '')