Esempio n. 1
0
 def setUp(self):
     self.old_cwd = os.getcwd()
     os.chdir(TEST_DIR)
     Module().create("Quux")
     os.chdir("Quux")
     self.layout = Layout()
Esempio n. 2
0
class LayoutTest(unittest.TestCase):

    def setUp(self):
        self.old_cwd = os.getcwd()
        os.chdir(TEST_DIR)
        Module().create("Quux")
        os.chdir("Quux")
        self.layout = Layout()

    def tearDown(self):
        os.chdir("..")
        remove_module("Foo", "Quux")
        os.chdir(self.old_cwd)
        del self.layout

    def test_create(self):
        file_name = "quux.xml"
        self.layout.create(file_name)
        try:
            with open(os.path.join(LAYOUT_DIR, file_name)) as layout_file:
                self.assertEqual(XML, layout_file.read())
        finally:
            os.remove(os.path.join(LAYOUT_DIR, file_name))
        with open(os.path.join("etc", "config.xml")) as config:
            self.assertEqual(CONFIG, config.read())

    def test_create_without_file_extension(self):
        file_name = "quux"
        self.layout.create(file_name)
        try:
            with open(os.path.join(LAYOUT_DIR, file_name + ".xml")) as layout_file:
                self.assertEqual(XML, layout_file.read())
        finally:
            os.remove(os.path.join(LAYOUT_DIR, file_name + ".xml"))
        with open(os.path.join("etc", "config.xml")) as config:
            self.assertEqual(CONFIG, config.read())

    def test_create_works_in_depth(self):
        file_name = "quux.xml"
        os.chdir("etc")
        self.layout.create(file_name)
        os.chdir("..")
        try:
            with open(os.path.join(LAYOUT_DIR, file_name)) as layout_file:
                self.assertEqual(XML, layout_file.read())
        finally:
            os.remove(os.path.join(LAYOUT_DIR, file_name))
        with open(os.path.join("etc", "config.xml")) as config:
            self.assertEqual(CONFIG, config.read())


    def test_register(self):
        self.layout.register("quux")
        with open(os.path.join("etc", "config.xml")) as config:
            self.assertEqual(CONFIG, config.read())

    def test_register_twice(self):
        self.layout.register("quux")
        self.layout.register("quux")
        with open(os.path.join("etc", "config.xml")) as config:
            self.assertEqual(CONFIG, config.read())