Skip to content

Instantly share code, notes, and snippets.

@dastanko
Created December 10, 2013 04:47
Show Gist options
  • Save dastanko/7885859 to your computer and use it in GitHub Desktop.
Save dastanko/7885859 to your computer and use it in GitHub Desktop.
#coding=utf-8
from unittest import TestCase
class XmlSerializable(object):
def to_xml(self):
raise NotImplementedError("This must implemented in all XmlSerializable objects")
class Document(XmlSerializable):
pass
class OriginalParser(object):
def __init__(self, text):
self._errors = []
self._text = text
@property
def text(self):
self._text
@text.setter
def text(self, value):
self._text = value
@property
def errors(self):
self.errors
def find_name(self):
pass
def find_published_date(self):
pass
def find_place(self):
pass
def find_revisions(self):
pass
def find_description(self):
pass
def find_content(self):
pass
class DocumentBuilder(object):
@property
def parser(self):
self._parser
@parser.setter
def parser(self, value):
self._parser = value
def build(self):
document = Document()
document.name = self._parser.find_name()
document.published_date = self._parser.find_published_date()
document.place = self._parser.find_place()
document.revisions = self._parser.find_revisions()
document.description = self._parser.find_description()
document.content = self._parser.find_content()
document.errors = self._parser.errors
return document
class BuilderTest(TestCase):
def test_build_name_in_one_line(self):
text = ""
builder = DocumentBuilder()
builder.parser = OriginalParser(text)
document = builder.build()
document.to_xml()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment