Пример #1
0
class Base(unittest.TestCase):
    """A base for testing all of the example sites. Default to the 'empty'
    example site.
    """
    def setUp(self, directory=os.path.join(examples_directory, "empty")):
        "Figure out the directories and build the site."
        self.directory = directory
        # create a Site object
        self.site = Site(self.directory)
        # get the build directory from the site's configuration
        self.build_dir = os.path.join(self.site.source,
                                      self.site.config.build_dir)
        # delete the build directory, just in case there's something there.
        self.delete_build_dir()
        # and, finally, build the site
        self.site.build()

    def delete_build_dir(self):
        "Delete the build directory."
        if os.path.exists(self.build_dir):
            shutil.rmtree(self.build_dir)

    def tearDown(self):
        "Delete the build directory after all the tests are done."
        self.delete_build_dir()

    def test_basic(self):
        "Check for basic decency in a built cytoplasm site."
        # check that the build directory was created
        self.assertTrue(os.path.exists(self.build_dir))
        # check that the build directory is, in fact, a directory
        self.assertTrue(os.path.isdir(self.build_dir))

    def test_copy_html(self):
        """Test whether building a cytoplasm site correctly copies over the
        uninterpreted files."""
        # a filter to tell whether files are html files and are not
        # configuration files.
        filter = lambda x: x.endswith(".html") and not x.startswith("_")
        # the html files in the source directory:
        in_source_dir = [
            file for file in os.listdir(self.directory) if filter(file)
        ]
        # the html files in the build dir:
        in_build_dir = [
            file for file in os.listdir(self.build_dir) if filter(file)
        ]
        # If nothing bad has happenned, everything in in_source_dir should be
        # in in_build_dir
        self.assertTrue(set(in_source_dir) <= set(in_build_dir))
        # Furthermore, the contents of each of these files should be the same.
        for source_path in in_source_dir:
            # open each of these files from their respective directories
            source_file = open(os.path.join(self.directory, source_path), "rb")
            built_file = open(os.path.join(self.build_dir, source_path), "rb")
            # assert that their contents are the same
            self.assertEqual(source_file.read(), built_file.read())
            # and then close each file
            source_file.close()
            built_file.close()
Пример #2
0
class Base(unittest.TestCase):
    """A base for testing all of the example sites. Default to the 'empty'
    example site.
    """
    def setUp(self, directory=os.path.join(examples_directory, "empty")):
        "Figure out the directories and build the site."
        self.directory = directory
        # create a Site object
        self.site = Site(self.directory)
        # get the build directory from the site's configuration
        self.build_dir = os.path.join(self.site.source,
                self.site.config.build_dir)
        # delete the build directory, just in case there's something there.
        self.delete_build_dir()
        # and, finally, build the site
        self.site.build()

    def delete_build_dir(self):
        "Delete the build directory."
        if os.path.exists(self.build_dir):
            shutil.rmtree(self.build_dir)

    def tearDown(self):
        "Delete the build directory after all the tests are done."
        self.delete_build_dir()

    def test_basic(self):
        "Check for basic decency in a built cytoplasm site."
        # check that the build directory was created
        self.assertTrue(os.path.exists(self.build_dir))
        # check that the build directory is, in fact, a directory
        self.assertTrue(os.path.isdir(self.build_dir))

    def test_copy_html(self):
        """Test whether building a cytoplasm site correctly copies over the
        uninterpreted files."""
        # a filter to tell whether files are html files and are not
        # configuration files.
        filter = lambda x: x.endswith(".html") and not x.startswith("_")
        # the html files in the source directory:
        in_source_dir = [file for file in os.listdir(self.directory) if
                filter(file)]
        # the html files in the build dir:
        in_build_dir = [file for file in os.listdir(self.build_dir) if
                filter(file)]
        # If nothing bad has happenned, everything in in_source_dir should be
        # in in_build_dir
        self.assertTrue(set(in_source_dir) <= set(in_build_dir))
        # Furthermore, the contents of each of these files should be the same.
        for source_path in in_source_dir:
            # open each of these files from their respective directories
            source_file = open(os.path.join(self.directory, source_path), "rb")
            built_file = open(os.path.join(self.build_dir, source_path), "rb")
            # assert that their contents are the same
            self.assertEqual(source_file.read(), built_file.read())
            # and then close each file
            source_file.close()
            built_file.close()
Пример #3
0
 def setUp(self, directory=os.path.join(examples_directory, "empty")):
     "Figure out the directories and build the site."
     self.directory = directory
     # create a Site object
     self.site = Site(self.directory)
     # get the build directory from the site's configuration
     self.build_dir = os.path.join(self.site.source,
                                   self.site.config.build_dir)
     # delete the build directory, just in case there's something there.
     self.delete_build_dir()
     # and, finally, build the site
     self.site.build()
Пример #4
0
 def setUp(self, directory=os.path.join(examples_directory, "empty")):
     "Figure out the directories and build the site."
     self.directory = directory
     # create a Site object
     self.site = Site(self.directory)
     # get the build directory from the site's configuration
     self.build_dir = os.path.join(self.site.source,
             self.site.config.build_dir)
     # delete the build directory, just in case there's something there.
     self.delete_build_dir()
     # and, finally, build the site
     self.site.build()