示例#1
0
def main_compile_sources(project, logger): #TODO rm prefix
    import string
    
    # Overwrite src/doc/conf.py with src/doc/_conf.py
    # and substitute $version, ... in the process.
    _conf_py = 'src/doc/_conf.py'
    conf_py = 'src/doc/conf.py'
    with open(_conf_py) as f:
        contents = f.read()
    contents = string.Template(contents).safe_substitute(ProjectDictWrapper(project, logger))
    contents = '# Generated by pyb, do not edit, edit _conf.py instead.\n\n' + contents
    with open(conf_py, 'w') as f:
        f.write(contents)
        
    # README.rst
    # - Overwrite README.rst with src/project/README.rst with $version substituted for project.version or 'latest'
    # - Set project.description
    with open(readme_file) as f:
        contents = f.read()
    contents = string.Template(contents).safe_substitute({
        'latest_or_version': project.version if project.get_property('is_release') else 'latest',
        'master_or_version': project.version if project.get_property('is_release') else 'master'
    })
    with open('README.rst', 'w') as f:
        f.write(contents)
    project.description = contents
    def test_should_return_project_property_when_property_is_defined(self):
        project_mock = Mock(Project)
        project_mock.name = "my name"

        self.assertEqual("my name", ProjectDictWrapper(project_mock, Mock())["name"])

        project_mock.get_property.assert_not_called()
示例#3
0
    def test_should_return_project_property_when_property_is_defined(self):
        project_mock = Mock(Project)
        project_mock.name = "my name"

        self.assertEquals("my name",
                          ProjectDictWrapper(project_mock, Mock())["name"])

        verify(project_mock, NEVER).get_property("name", "name")
    def test_should_delegate_to_project_get_property_when_attribute_is_not_defined(self):
        project_mock = Project(".")
        project_mock.has_property = Mock(return_value=True)
        project_mock.get_property = Mock(return_value="eggs")

        self.assertEqual("eggs", ProjectDictWrapper(project_mock, Mock())["spam"])

        project_mock.get_property.assert_called_with("spam")
    def test_should_delegate_to_project_get_property_when_attribute_is_not_defined(
            self):
        project_mock = Project(".")
        when(project_mock).get_property("spam", "spam").thenReturn("eggs")

        self.assertEquals("eggs", ProjectDictWrapper(project_mock)["spam"])

        verify(project_mock).get_property("spam", "spam")
    def test_should_warn_when_substitution_is_skipped(self):
        project_mock = Project(".")
        logger_mock = Mock()
        project_mock.has_property = Mock(return_value=False)
        project_mock.get_property = Mock()

        self.assertEqual("${n/a}", ProjectDictWrapper(project_mock, logger_mock)["n/a"])

        project_mock.get_property.assert_not_called()
        logger_mock.warn.assert_called_with(
            "Skipping impossible substitution for 'n/a' - there is no matching project attribute or property.")
示例#7
0
    def test_should_warn_when_substitution_is_skipped(self):
        project_mock = Project(".")
        logger_mock = Mock()
        when(project_mock).has_property("n/a").then_return(False)

        self.assertEquals("${n/a}",
                          ProjectDictWrapper(project_mock, logger_mock)["n/a"])

        verify(project_mock, NEVER).get_property("n/a")
        verify(logger_mock).warn(
            "Skipping impossible substitution for 'n/a' - there is no matching project attribute or property."
        )
    def test_should_return_project_property_when_property_is_defined(self):
        project_mock = mock(Project, name="my name")

        self.assertEquals("my name", ProjectDictWrapper(project_mock)["name"])

        verify(project_mock, never).get_property("name", "name")