示例#1
0
    def setUp(self):
        os.putenv("GIT_DIR", git_dir)
        os.putenv("GIT_WORK_TREE", working_dir) 
        execute("git init")
        
        setup = Setup(project_folder, working_dir, git_dir)
        setup.run()

        self.config = Config(working_dir)
        self.path = Path(self.config)
        self.parser = Parser(self.config)

        self.changelog_abspath = self.path.get_changelog_abspath()
        self.git_dir =self.path.get_git_dir()
示例#2
0
class ParserTestCase(unittest.TestCase):

    def setUp(self):
        os.putenv("GIT_DIR", git_dir)
        os.putenv("GIT_WORK_TREE", working_dir) 
        execute("git init")
        
        setup = Setup(project_folder, working_dir, git_dir)
        setup.run()

        self.config = Config(working_dir)
        self.path = Path(self.config)
        self.parser = Parser(self.config)

        self.changelog_abspath = self.path.get_changelog_abspath()
        self.git_dir =self.path.get_git_dir()
    
    def test_init(self):
        assert self.parser.config == self.config
        #assert self.parser.source_dir == source_dir
        
    def test_get_fragment(self):
        fragment = self.parser.get_fragment(source_abspath)
        excerpt = "connecting things"
        assert excerpt in fragment
        
    def test_get_data(self):
        data = self.parser.get_data(source_abspath)
        assert data['title'] == title
        assert data['subtitle'] == subtitle
        assert excerpt in data['fragment'] 
        assert  data['docid'] == docid
        assert  data['author'] == author
        assert  data['date'] == date
        assert  data['tags'] == tags
        assert  data['slug'] == slug
        assert  data['fragment_path'] == fragment_path
        assert  data['source_path'] == source_path
        
    def test_get_document_source(self):
        source = self.parser.get_document_source(source_abspath)
        assert docid in source
        assert excerpt in source

    def test_get_document_parts(self):
        source = self.parser.get_document_source(source_abspath)
        parts = self.parser.get_document_parts(source)

        assert parts['title'] == title
        assert parts['subtitle'] == subtitle
        assert excerpt in parts['fragment'] 
                
    def test_get_substition_defintions(self):
        source = self.parser.get_substitution_definitions()
        assert "isopub" in source
        assert "en dash" in source
        assert "em dash" in source
        
    def test_read_source_file(self):
        source = self.parser.read_source_file(source_abspath)
        assert docid in source
        assert excerpt in source

    def test_get_slug(self):
        slug = self.parser.get_slug(source_abspath)
        assert slug == "lightbulb"

    def test_get_source_dir(self):
        source_dir = self.path.get_source_dir()
        assert source_dir == source_dir
        
    def test_get_source_path(self):
        source_path = self.path.get_source_path(source_abspath)
        assert source_path == "lightbulb.rst"

    def test_get_fragment_abspath(self):
        fragment_abspath = self.path.get_fragment_abspath(source_abspath)
        assert fragment_abspath == "%s/lightbulb.html" % build_dir

    def test_get_fragment_path(self):
        fragment_path = self.path.get_fragment_path(source_abspath)
        assert fragment_path == "lightbulb.html" 
        
    def test_get_metadata(self):
        source = self.parser.get_document_source(source_abspath)
        meta = self.parser._get_metadata(source, source_abspath)

        assert  meta['docid'] == docid
        assert  meta['author'] == author
        assert  meta['date'] == date
        assert  meta['tags'] == tags

    def test_process_standard_fields(self):
        source = self.parser.get_document_source(source_abspath)
        doctree = docutils.core.publish_doctree(source)
        docinfo = doctree.traverse(docutils.nodes.docinfo)
        meta = self.parser._process_standard_fields(docinfo)

        assert  meta['author'] == author
        assert  meta['date'] == date

    def test_process_custom_fields(self):
        source = self.parser.get_document_source(source_abspath)
        doctree = docutils.core.publish_doctree(source)
        docinfo = doctree.traverse(docutils.nodes.docinfo)
        meta = self.parser._process_standard_fields(docinfo)
        meta = self.parser._process_custom_fields(meta)
        
        assert 'docid' in meta.keys()
        assert 'tags' in meta.keys()

    def test_get_all_files(self):
        source_files = list(self.parser.get_all_files())
        
        assert source_abspath in source_files
        assert another_file in source_files