def test_list_mismatch(self): resource = StringIO( "[{!Assembly Hello: [A]}, {!Assembly Hello: {Foo: Bar}}]") with LogCapture() as l: result = run(StringIO(""), [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!map value at", err) self.assertIn("into !!seq value at", err) resource = StringIO("[{!Assembly Hello: [A]}, {!Assembly Hello: X}]") with LogCapture() as l: result = run(StringIO(""), [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!str value at", err) self.assertIn("into !!seq value at", err) template = StringIO("[{!Transclude Hello: {Foo: Bar}}]") resource = StringIO("[{!Assembly Hello: [A]}]") with LogCapture() as l: result = run(template, [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!seq value at", err) self.assertIn("into !!map value at", err)
def transclude(self): result = run(self.template_document, self.resource_documents, self.output_temp, self.local_tags) if result != 0: raise ValueError("Transclusion error -- see above messages for " "details.") return
def test_dict_duplicate(self): resource = StringIO( "[{!Assembly Hello: {A: B, C: D}}, {!Assembly Hello: {C: D}}]") with LogCapture() as l: result = run(StringIO(""), [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge duplicate mapping key 'C' at", err) self.assertIn("into existing mapping at", err) template = StringIO("[{!Transclude Hello: {C: D}}]") resource = StringIO("[{!Assembly Hello: {A: B, C: D}}]") with LogCapture() as l: result = run(template, [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge duplicate mapping key 'C' at", err) self.assertIn("into existing mapping at", err)
def test_set_mismatch(self): resource = StringIO("- !Assembly Hello: !!set\n" " ? A\n" "- !Assembly Hello: [bar]") with LogCapture() as l: result = run(StringIO(""), [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!seq value at", err) self.assertIn("into !!set value at", err) resource = StringIO("- !Assembly Hello: !!set\n" " ? A\n" "- !Assembly Hello: X") with LogCapture() as l: result = run(StringIO(""), [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!str value at", err) self.assertIn("into !!set value at", err) template = StringIO("[{!Transclude Hello: [Bar]}]") resource = StringIO("- !Assembly Hello: !!set\n" " ? A\n") with LogCapture() as l: result = run(template, [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!set value at", err) self.assertIn("into !!seq value at", err) template = StringIO("[{!Transclude Hello: X}]") resource = StringIO("- !Assembly Hello: !!set\n" " ? A\n") with LogCapture() as l: result = run(template, [resource], StringIO(), True) self.assertEquals(result, 1) err = str(l) self.assertIn("Cannot merge !!set value at", err) self.assertIn("into !!str value at", err)
def test_multiple_transcludes(self): template = StringIO("{!Transclude Hello: X, !Transclude World: Y}") with LogCapture() as l: result = run(template, [], StringIO(), True) self.assertEquals(result, 1) self.assertIn("Transclude must be a single-entry mapping", str(l))
def test_multiple_assemblies(self): resource = StringIO("{!Assembly Hello: X, !Assembly World: Y}") with LogCapture() as l: result = run(StringIO(""), [resource], StringIO(), True) self.assertEquals(result, 1) self.assertIn("Assembly must be a single-entry mapping", str(l))