def test_create_files_with_python(self): """test create_files call and content of files""" opts = mock.Mock() opts.repo = self.repo opts.create_version_file = True opts.source = 'src' opts.version = '0.0.1' opts.version_file = None opts.org = "ORG" opts.desc = "DESCRIPTION" opts.templates = [] opts.test_mode = False opts.history_file = 'HISTORY.md' opts.package = 'unittests' opts.develop = 'develop' opts.requirements = 'requirements.txt' opts.pypi_package_name = 'pypi.package.unittest' opts.python = 'python3' opts.test_requirements = 'test-requirements.txt' version = os.path.join(self.repo, 'src', 'unittests', '__init__.py') os.system('rm -f {}'.format(version)) create_files(opts) dir_list = os.listdir(self.repo) self.failUnless('cirrus.conf' in dir_list) self.failUnless('HISTORY.md' in dir_list) self.failUnless('MANIFEST.in' in dir_list) self.failUnless('setup.py' in dir_list) cirrus_conf = os.path.join(self.repo, 'cirrus.conf') config = ConfigParser.RawConfigParser() config.read(cirrus_conf) self.assertEqual(config.get('package', 'name'), opts.pypi_package_name) self.assertEqual(config.get('package', 'version'), opts.version) self.assertEqual(config.get('build', 'python'), 'python3')
def write_cirrus_conf(opts, version_file): """ build the basic cirrus config file and write it out """ cirrus_conf = os.path.join(opts.repo, 'cirrus.conf') LOGGER.info("setting up cirrus.conf: {}".format(cirrus_conf)) backup_file(cirrus_conf) pname = opts.package if opts.pypi_package_name: pname = opts.pypi_package_name config = ConfigParser.ConfigParser() config.add_section('package') config.set('package', 'name', pname) config.set('package', 'version', str(opts.version)) config.set('package', 'description', str(opts.desc)) config.set('package', 'organization', str(opts.org)) config.set('package', 'version_file', version_file) config.set('package', 'history_file', opts.history_file) config.set('package', 'author', os.environ['USER']) config.set('package', 'author_email', 'EMAIL_HERE') config.set('package', 'url', 'PACKAGE_URL_HERE') if opts.source: config.set('package', 'find_packages', str(opts.source)) config.add_section('gitflow') config.set('gitflow', 'origin_name', str(opts.origin)) config.set('gitflow', 'develop_branch', str(opts.develop)) config.set('gitflow', 'release_branch_prefix', 'release/') config.set('gitflow', 'feature_branch_prefix', 'feature/') config.add_section('build') if os.path.exists(opts.test_requirements): config.set('build', 'extra_requirements', opts.test_requirements) if opts.python: config.set('build', 'python', opts.python) if opts.use_pypirc: rcfile = PypircFile() pip_opts = rcfile.pip_options() LOGGER.info("Adding pip options to cirrus.conf: {}".format(pip_opts)) config.set('build', 'pip_options', pip_opts) config.add_section('pypi') config.set('pypi', 'pip_options', pip_opts) config.add_section('test-default') config.set('test-default', 'where', 'tests/unit') config.set('test-default', 'mode', str(opts.test_mode)) config.add_section('qc') config.set('qc', 'threshold', str(10)) config.set('qc', 'include_files', 'src/{}/*'.format(opts.package)) config.set('qc', 'exclude_dirs', 'tests dist venv .tox') config.set('qc', 'linters', "Pep8 Pyflakes") config.add_section("qc/Pep8") config.set("qc/Pep8", "allowed_errors_per_file", str(5)) config.add_section("qc/Pyflakes") config.set("qc/Pyflakes", "allowed_errors_per_file", str(5)) with open(cirrus_conf, 'w') as handle: config.write(handle) return cirrus_conf
def load(self): """parse config file into self""" self.parser = ConfigParser.RawConfigParser() self.parser.read(self.config_file) for section in self.parser.sections(): self.setdefault(section, {}) for option in self.parser.options(section): self[section].setdefault(option, self.parser.get(section, option))
def setUp(self): """set up a test gitconfig""" self.dir = tempfile.mkdtemp() self.gitconfig = os.path.join(self.dir, '.gitconfig') gitconf = ConfigParser.RawConfigParser() gitconf.add_section('cirrus') gitconf.set('cirrus', 'credential-plugin', 'default') gitconf.set('cirrus', 'github-user', 'steve') gitconf.set('cirrus', 'github-token', 'steves token') with open(self.gitconfig, 'w') as handle: gitconf.write(handle)
def setUp(self): """create a sample conf file""" self.dir = tempfile.mkdtemp() self.test_file = os.path.join(self.dir, 'cirrus.conf') self.gitconfig = os.path.join(self.dir, '.gitconfig') self.patch_env = mock.patch.dict(os.environ, { 'HOME': self.dir, 'USER': '******' }) self.patch_env.start() parser = ConfigParser.RawConfigParser() parser.add_section('package') parser.add_section('gitflow') parser.add_section('extras_require') parser.set('package', 'name', 'cirrus_tests') parser.set('package', 'version', '1.2.3') parser.set('gitflow', 'develop_branch', 'develop') parser.set('gitflow', 'release_branch_prefix', 'release/') parser.set('gitflow', 'feature_branch_prefix', 'feature/') parser.set('extras_require', 'analysis', 'pandas;scipy') parser.set('extras_require', 'server', 'Flask==0.0.0') with open(self.test_file, 'w') as handle: parser.write(handle) gitconf = ConfigParser.RawConfigParser() gitconf.add_section('cirrus') gitconf.set('cirrus', 'credential-plugin', 'default') with open(self.gitconfig, 'w') as handle: gitconf.write(handle) self.gitconf_str = "cirrus.credential-plugin=default" self.patcher = mock.patch('cirrus.plugins.creds.default.os') default_os = self.patcher.start() default_os.path = mock.Mock() default_os.path.join = mock.Mock() default_os.path.join.return_value = self.gitconfig
def test_create_files_with_version(self): """test create_files call and content of files""" opts = mock.Mock() opts.repo = self.repo opts.create_version_file = True opts.source = 'src' opts.version = '0.0.1' opts.org = "ORG" opts.version_file = None opts.test_mode = 'False' opts.desc = "DESCRIPTION" opts.templates = ['include steve/*'] opts.history_file = 'HISTORY.md' opts.package = 'unittests' opts.requirements = 'requirements.txt' opts.pypi_package_name = None opts.develop = 'develop' opts.python = None opts.gitignore_url = "GIT_IGNORE_URL" opts.add_gitignore = False opts.test_requirements = 'test-requirements.txt' version = os.path.join(self.repo, 'src', 'unittests', '__init__.py') os.system('rm -f {}'.format(version)) create_files(opts) dir_list = os.listdir(self.repo) self.failUnless('cirrus.conf' in dir_list) self.failUnless('HISTORY.md' in dir_list) self.failUnless('MANIFEST.in' in dir_list) self.failUnless('setup.py' in dir_list) cirrus_conf = os.path.join(self.repo, 'cirrus.conf') config = ConfigParser.RawConfigParser() config.read(cirrus_conf) self.assertEqual(config.get('package', 'name'), opts.package) self.assertEqual(config.get('package', 'version'), opts.version) history = os.path.join(self.repo, 'HISTORY.md') with open(history, 'r') as handle: self.failUnless('CIRRUS_HISTORY_SENTINEL' in handle.read()) manifest = os.path.join(self.repo, 'MANIFEST.in') with open(manifest, 'r') as handle: content = handle.read() self.failUnless('include requirements.txt' in content) self.failUnless('include cirrus.conf' in content) self.failUnless('include steve/*' in content) version = os.path.join(self.repo, 'src', 'unittests', '__init__.py') with open(version, 'r') as handle: self.failUnless(opts.version in handle.read())
def write_cirrus_conf(opts, version_file): """ build the basic cirrus config file and write it out """ cirrus_conf = os.path.join(opts.repo, 'cirrus.conf') LOGGER.info("setting up cirrus.conf: {}".format(cirrus_conf)) backup_file(cirrus_conf) pname = opts.package if opts.pypi_package_name: pname = opts.pypi_package_name config = ConfigParser.ConfigParser() config.add_section('package') config.set('package', 'name', pname) config.set('package', 'version', str(opts.version)) config.set('package', 'description', str(opts.desc)) config.set('package', 'organization', str(opts.org)) config.set('package', 'version_file', version_file) config.set('package', 'history_file', opts.history_file) config.set('package', 'author', os.environ['USER']) config.set('package', 'author_email', 'EMAIL_HERE') config.set('package', 'url', 'PACKAGE_URL_HERE') if opts.source: config.set('package', 'find_packages', str(opts.source)) config.add_section('gitflow') config.set('gitflow', 'develop_branch', str(opts.develop)) config.set('gitflow', 'release_branch_prefix', 'release/') config.set('gitflow', 'feature_branch_prefix', 'feature/') config.add_section('build') if os.path.exists(opts.test_requirements): config.set('build', 'extra_requirements', opts.test_requirements) if opts.python: config.set('build', 'python', opts.python) config.add_section('test-default') config.set('test-default', 'where', 'tests/unit') config.set('test-default', 'mode', str(opts.test_mode)) config.add_section('quality') config.set('quality', 'threshold', str(10)) with open(cirrus_conf, 'w') as handle: config.write(handle) return cirrus_conf
def load(self): """ _load_from_file_ Reread the cirrus config file """ self.parser = ConfigParser.RawConfigParser() self.parser.read(self.config_file) for section in self.parser.sections(): self.setdefault(section, {}) for option in self.parser.options(section): self[section].setdefault(option, self.parser.get(section, option)) if self.gitconfig_file is None: self.gitconfig_file = os.path.join(os.environ['HOME'], '.gitconfig') self.gitconfig = load_gitconfig(self.gitconfig_file) self._load_creds_plugin()
def write_cirrus_conf(config_file, **sections): """ _write_cirrus_conf_ Util to create a cirrus configuration file and populate it with the settings for the package, gitflow, pypi etc sections. sections should be nested dict of the form {sectionname: {sectionsettings}} Eg: settings={'package': {'name': 'package_name'} } """ parser = ConfigParser.RawConfigParser() for section, settings in iter(sections.items()): parser.add_section(section) for key, value in iter(settings.items()): parser.set(section, key, value) with open(config_file, 'w') as handle: parser.write(handle)