def test_multiple_char_end(self): """Tests inserting multiple characters at the end of the file """ index = len(self.file_data) insertion = "gasdf asdfwwr\n asdf" expected = self.data_insert(insertion, index) with open(self.test_file_path, "r+") as test_file: insert(insertion, test_file, index) actual = self.file_contents self.assertEqual(actual, expected)
def test_single_char_start(self): """Tests inserting a single character at the start of the file """ index = 0 insertion = "g" expected = self.data_insert(insertion, index) with open(self.test_file_path, "r+") as test_file: insert(insertion, test_file, index) actual = self.file_contents self.assertEqual(actual, expected)
def test_empty_end(self): """Tests inserting an empty string at the end of the file """ index = len(self.file_data) insertion = "" expected = self.data_insert(insertion, index) with open(self.test_file_path, "r+") as test_file: insert(insertion, test_file, index) actual = self.file_contents self.assertEqual(actual, expected)
def test_empty_insertion(self): """Tests the function when the string inserted is empty """ index = 11 insertion = "" expected = self.data_insert(insertion, index) with open(self.test_file_path, "r+") as test_file: insert(insertion, test_file, index) actual = self.file_contents self.assertEqual(actual, expected)
def test_multiple_char_middle(self): """Tests inserting multiple characters somewhere in the middle of the file """ index = 11 insertion = "gasdf asdfwwr\n asdf" expected = self.data_insert(insertion, index) with open(self.test_file_path, "r+") as test_file: insert(insertion, test_file, index) actual = self.file_contents self.assertEqual(actual, expected)
async def coroutine(self, data): """This function dictionaries to a json file for using in LightTag data sets. Args: data (:obj:`dict`): A dictionary containing data that needs to be tagged """ file_path = get_training_file_path("LightTag-dataset.json") is_new_file = create_file(file_path, "[\n]") data_string = json.dumps(data) prefix = "\n" if is_new_file else ",\n" insertion_string = "{0}{1}".format(prefix, data_string) with open(file_path, "r+") as json_file: json_file.seek(0, 2) position = json_file.tell() - 2 insert(insertion_string, json_file, position)