def test_3_str_merge_with_comment(self): str1 = """ #comment1 test: foo: 1 #comment1 #ninja-comment1 bar: 1 """ str2 = """ test: #ninja-comment2 foo: 2 """ str3 = """ test: bar: "3" #comment3 foobar: 3 #comment3 #ninja-comment3 """ out = yaml_tools.successive_merge([str1, str2, str3]) expected_out = round_trip_load(self.merge_str_out, preserve_quotes=True) yml = MyYAML() out_str = yml.dump(out) expected_out_str = yml.dump(expected_out) self.assertEqual(out_str, expected_out_str)
def test_merge_None_to_any(self): out = yaml_tools.successive_merge([self.mock_None, self.mock_None]) expected_out = round_trip_load(self.mock_None, preserve_quotes=True) self.assertEqual(out, expected_out, 'Merge None to None should succeed') out = yaml_tools.successive_merge([self.mock_scalar_1, self.mock_None]) expected_out = round_trip_load(self.mock_scalar_1, preserve_quotes=True) self.assertEqual(out, expected_out, 'Merge None to scalar should succeed') out = yaml_tools.successive_merge([self.mock_dict_1, self.mock_None]) expected_out = round_trip_load(self.mock_dict_1, preserve_quotes=True) self.assertEqual(out, expected_out, 'Merge None to dict should succeed') out = yaml_tools.successive_merge([self.mock_list_1, self.mock_None]) expected_out = round_trip_load(self.mock_list_1, preserve_quotes=True) self.assertEqual(out, expected_out, 'Merge None to list should succeed')
def test_merge_list_to_list(self): out = yaml_tools.successive_merge([self.mock_list_1, self.mock_list_2]) expected_out_str = """ test: - item1 - item2 - item3 """ expected_out = round_trip_load(expected_out_str, preserve_quotes=True) self.assertEqual(out, expected_out)
def test_merge_list_to_scalar(self): out = yaml_tools.successive_merge( [self.mock_scalar_1, self.mock_list_2]) expected_out_str = """ test: - item3 - 1 """ # the scalar is appended at the end of the list expected_out = round_trip_load(expected_out_str, preserve_quotes=True) self.assertEqual(out, expected_out)
def test_merge_dict_to_dict(self): out = yaml_tools.successive_merge([self.mock_dict_1, self.mock_dict_2]) expected_out_str = """ test: foo: 1 bar: 2 foobar: babar """ expected_out = round_trip_load(expected_out_str, preserve_quotes=True) self.assertEqual(out, expected_out)
def test_merge_list_to_None(self): out = yaml_tools.successive_merge(['test: ', self.mock_list_2]) expected_out = round_trip_load(self.mock_list_2, preserve_quotes=True) self.assertEqual(out, expected_out)
def test_merge_scalar_to_scalar(self): out = yaml_tools.successive_merge( [self.mock_scalar_1, self.mock_scalar_2]) expected_out = round_trip_load(self.mock_scalar_2, preserve_quotes=True) self.assertEqual(out, expected_out)