def test_from_merged_snippets_overlapping_forbidden(self): """ Tests creating a snippet collection from two other collections. """ original1 = snippets.Snippets({"A": "a", "C": "c", "B": "b"}) original2 = snippets.Snippets({"B": "x", "Y": "y", "Z": "z"}) with self.assertRaises(snippets.SnippetsException): original1.merge_with(original2)
def test_from_merged_snippets_overlapping_allowed(self): """ Tests creating a snippet collection from two other collections. """ original1 = snippets.Snippets({"A": "a", "C": "c", "B": "b"}) original2 = snippets.Snippets({"B": "x", "Y": "y", "Z": "z"}) result = original1.merge_with(original2, check_overlapping=False) expected = {"A": "a", "B": "x", "C": "c", "Y": "y", "Z": "z"} self.assertEqual(result.to_dict(), expected)
def test_from_snippets_subset(self): """ Tests creating a snippet collection that is a subset of another one. """ original = snippets.Snippets({"A": "a", "C": "c", "B": "b"}) result = original.subset(["A", "C"]) expected = {"A": "a", "C": "c"} self.assertEqual(result.to_dict(), expected)
def test_add_snippet(self): """ Test creation from dict with valid data. """ snippet_dict = {"A": "a", "B": "b", "C": "c"} original = snippets.Snippets(snippet_dict) result = original.add("X", "x") expected = {"A": "a", "B": "b", "C": "c", "X": "x"} self.assertEqual(expected, result.to_dict())
def test_from_snippets_renamed(self): """ Tests creating a snippet collection that is a renamed version of another. """ original = snippets.Snippets({"A": "a", "C": "c", "B": "b"}) name_map = {"A": "X", "B": "B", "C": "Z"} result = original.renamed(name_map) expected = {"X": "a", "B": "b", "Z": "c"} self.assertEqual(result.to_dict(), expected)
def test_transform(self): """ Tests creating snippet collections from other snippet collections. """ original = snippets.Snippets({"A": "a", "C": "c", "B": "b"}) new = original.transform() self.assertEqual(original.to_dict(), new.to_dict())
def test_str(self): """ Tests generating the string representaiton of a snippets instance. """ snippet_collection = snippets.Snippets({"A": "a", "C": "c", "B": "b"}) self.assertEqual("A\na\nB\nb\nC\nc\n", str(snippet_collection))