Skip to content

Commit

Permalink
Merge pull request #28 from jackwilsdon/test-improvements
Browse files Browse the repository at this point in the history
Add flake8 checks and more Python versions for testing
  • Loading branch information
jackwilsdon committed Jun 14, 2016
2 parents 883a5b9 + 0b07602 commit fd0001c
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 48 deletions.
48 changes: 35 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "pypy"
sudo: false

env:
global:
# Undocumented feature of nose-show-skipped.
NOSE_SHOW_SKIPPED: 1

matrix:
include:
- python: 2.7
env: {TOXENV: py27-test}
- python: 3.3
env: {TOXENV: py33-cov, COVERAGE: 1}
- python: 3.4
env: {TOXENV: py34-test}
- python: 3.5
env: {TOXENV: py35-test}
- python: pypy
env: {TOXENV: pypy-test}
- python: 2.7
env: {TOXENV: py27-flake8}
- python: 3.3
env: {TOXENV: py33-flake8}
- python: 2.7
env: {TOXENV: docs}

# To install dependencies, tell tox to do everything but actually running the
# test.
install:
- pip install .
- travis_retry python setup.py test -a "--notest"

script: nosetests --with-coverage --cover-package=confuse
script: python setup.py test

# coveralls.io reporting, using https://github.com/coagulant/coveralls-python
# Only report coverage for one version.
before_script:
- "[[ $TRAVIS_PYTHON_VERSION == '3.3' ]] && pip install coveralls || true"
# Report coverage to codecov.io.
before_install:
- "[ ! -z $COVERAGE ] && travis_retry pip install codecov || true"
after_success:
- "[[ $TRAVIS_PYTHON_VERSION == '3.3' ]] && coveralls || true"
- "[ ! -z $COVERAGE ] && codecov || true"

sudo: false
cache:
pip: true
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Don't post a comment on pull requests.
comment: off

# I think this disables commit statuses?
coverage:
status:
project:
enabled: no
patch:
enabled: no
changes:
enabled: no
7 changes: 4 additions & 3 deletions confuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import re
from collections import OrderedDict


UNIX_DIR_VAR = 'XDG_CONFIG_HOME'
UNIX_DIR_FALLBACK = '~/.config'
WINDOWS_DIR_VAR = 'APPDATA'
Expand All @@ -44,9 +45,9 @@
# Utilities.

PY3 = sys.version_info[0] == 3
STRING = str if PY3 else unicode
BASESTRING = str if PY3 else basestring
NUMERIC_TYPES = (int, float) if PY3 else (int, float, long)
STRING = str if PY3 else unicode # noqa ignore=F821
BASESTRING = str if PY3 else basestring # noqa ignore=F821
NUMERIC_TYPES = (int, float) if PY3 else (int, float, long) # noqa ignore=F821


def iter_first(sequence):
Expand Down
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import division, absolute_import, print_function


extensions = []
source_suffix = '.rst'
master_doc = 'index'
Expand All @@ -12,8 +15,7 @@

pygments_style = 'sphinx'

# -- Options for HTML output ---------------------------------------------------
# -- Options for HTML output --------------------------------------------------

html_theme = 'default'
html_static_path = ['_static']
htmlhelp_basename = 'Confusedoc'
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
import example

example.main()
4 changes: 2 additions & 2 deletions example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""An example application using Confuse for configuration."""
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division, absolute_import, print_function
import confuse
import argparse


template = {
'library': confuse.Filename(),
'import_write': confuse.OneOf([bool, 'ask', 'skip']),
Expand Down
20 changes: 20 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[nosetests]
verbosity=1
logging-clear-handlers=1
eval-attr="!=slow"

[flake8]
min-version=2.7
# Default pyflakes errors we ignore:
# - E241: missing whitespace after ',' (used to align visually)
# - E221: multiple spaces before operator (used to align visually)
# - E731: do not assign a lambda expression, use a def
# - C901: function/method complexity
# `flake8-future-import` errors we ignore:
# - FI50: `__future__` import "division" present
# - FI51: `__future__` import "absolute_import" present
# - FI12: `__future__` import "with_statement" missing
# - FI53: `__future__` import "print_function" present
# - FI14: `__future__` import "unicode_literals" missing
# - FI15: `__future__` import "generator_stop" missing
ignore=C901,E241,E221,E731,FI50,FI51,FI12,FI53,FI14,FI15
68 changes: 64 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
from setuptools import setup
from __future__ import division, absolute_import, print_function

import os
from os import path
import sys
from setuptools.dist import Distribution
from setuptools import setup, Command
import shlex


class CustomDistribution(Distribution):
def __init__(self, *args, **kwargs):
self.sdist_requires = None
Distribution.__init__(self, *args, **kwargs)

def get_finalized_command(self, command, create=1):
cmd_obj = self.get_command_obj(command, create)
cmd_obj.ensure_finalized()
return cmd_obj

def export_live_eggs(self, env=False):
"""Adds all of the eggs in the current environment to PYTHONPATH."""
path_eggs = [p for p in sys.path if p.endswith('.egg')]

command = self.get_finalized_command("egg_info")
egg_base = path.abspath(command.egg_base)

unique_path_eggs = set(path_eggs + [egg_base])

os.environ['PYTHONPATH'] = ':'.join(unique_path_eggs)


class test(Command): # noqa: ignore=N801
"""Command to run tox."""

description = "run tox tests"

user_options = [('tox-args=', 'a', "Arguments to pass to tox")]

def initialize_options(self):
self.tox_args = ''

def finalize_options(self):
pass

def run(self):
# Install test dependencies if needed.
if self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)

# Add eggs to PYTHONPATH. We need to do this to ensure our eggs are
# seen by Tox.
# Without this, Tox can't find it's dependencies.
self.distribution.export_live_eggs()

tox = __import__('tox')

parsed_args = shlex.split(self.tox_args)
result = tox.cmdline(args=parsed_args)

sys.exit(result)


def _read(fn):
Expand All @@ -17,10 +76,10 @@ def _read(fn):
license='MIT',
platforms='ALL',
long_description=_read("README.rst"),
install_requires=[
'pyyaml'
],
install_requires=['pyyaml'],
tests_require=['tox'],
py_modules=['confuse'],
cmdclass={'test': test},
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
Expand All @@ -30,4 +89,5 @@ def _read(fn):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
distclass=CustomDistribution
)
2 changes: 2 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division, absolute_import, print_function

import confuse
import tempfile
import shutil
Expand Down
5 changes: 5 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division, absolute_import, print_function

import confuse
import argparse
import optparse
Expand Down Expand Up @@ -36,6 +38,7 @@ def test_argument_overrides_default(self):
self._parse('--foo bar')
self.assertEqual(self.config['foo'].get(), 'bar')


class OptparseTest(unittest.TestCase):
def setUp(self):
self.config = confuse.Configuration('test', read=False)
Expand Down Expand Up @@ -68,10 +71,12 @@ def test_argument_overrides_default(self):
self._parse('--foo bar')
self.assertEqual(self.config['foo'].get(), 'bar')


class Namespace(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)


class GenericNamespaceTest(unittest.TestCase):
def setUp(self):
self.config = confuse.Configuration('test', read=False)
Expand Down
2 changes: 2 additions & 0 deletions test/test_dump.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division, absolute_import, print_function

import confuse
import textwrap
import unittest
Expand Down
17 changes: 11 additions & 6 deletions test/test_paths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division, absolute_import, print_function

import confuse
import ntpath
import os
Expand All @@ -7,10 +9,12 @@
import tempfile
import unittest


DEFAULT = [platform.system, os.environ, os.path]

SYSTEMS = {
'Linux': [{'HOME': '/home/test', 'XDG_CONFIG_HOME': '~/xdgconfig'},
posixpath],
posixpath],
'Darwin': [{'HOME': '/Users/test'}, posixpath],
'Windows': [{'APPDATA': '~\\winconfig', 'HOME': 'C:\\Users\\test'}, ntpath]
}
Expand Down Expand Up @@ -48,7 +52,7 @@ class LinuxTestCases(FakeSystem):

def test_both_xdg_and_fallback_dirs(self):
self.assertEqual(confuse.config_dirs(),
['/home/test/.config', '/home/test/xdgconfig'])
['/home/test/.config', '/home/test/xdgconfig'])

def test_fallback_only(self):
del os.environ['XDG_CONFIG_HOME']
Expand All @@ -64,21 +68,22 @@ class OSXTestCases(FakeSystem):

def test_mac_dirs(self):
self.assertEqual(confuse.config_dirs(),
['/Users/test/Library/Application Support', '/Users/test/.config'])
['/Users/test/Library/Application Support',
'/Users/test/.config'])


class WindowsTestCases(FakeSystem):
SYS_NAME = 'Windows'

def test_dir_from_environ(self):
self.assertEqual(confuse.config_dirs(),
['C:\\Users\\test\\AppData\\Roaming',
'C:\\Users\\test\\winconfig'])
['C:\\Users\\test\\AppData\\Roaming',
'C:\\Users\\test\\winconfig'])

def test_fallback_dir(self):
del os.environ['APPDATA']
self.assertEqual(confuse.config_dirs(),
['C:\\Users\\test\\AppData\\Roaming'])
['C:\\Users\\test\\AppData\\Roaming'])


class ConfigFilenamesTest(unittest.TestCase):
Expand Down
12 changes: 7 additions & 5 deletions test/test_valid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division, absolute_import, print_function

import confuse
import os
import collections
Expand Down Expand Up @@ -105,13 +107,13 @@ def test_concrete_string_as_template(self):

@unittest.skipIf(confuse.PY3, "unicode only present in Python 2")
def test_unicode_type_as_template(self):
typ = confuse.as_template(unicode)
typ = confuse.as_template(unicode) # noqa ignore=F821
self.assertIsInstance(typ, confuse.String)
self.assertEqual(typ.default, confuse.REQUIRED)

@unittest.skipIf(confuse.PY3, "basestring only present in Python 2")
def test_basestring_as_template(self):
typ = confuse.as_template(basestring)
typ = confuse.as_template(basestring) # noqa ignore=F821
self.assertIsInstance(typ, confuse.String)
self.assertEqual(typ.default, confuse.REQUIRED)

Expand Down Expand Up @@ -375,16 +377,16 @@ def test_filename_with_non_file_source(self):

def test_filename_with_file_source(self):
source = confuse.ConfigSource({'foo': 'foo/bar'},
filename='/baz/config.yaml')
filename='/baz/config.yaml')
config = _root(source)
config.config_dir = lambda: '/config/path'
valid = config['foo'].get(confuse.Filename())
self.assertEqual(valid, os.path.realpath('/config/path/foo/bar'))

def test_filename_with_default_source(self):
source = confuse.ConfigSource({'foo': 'foo/bar'},
filename='/baz/config.yaml',
default=True)
filename='/baz/config.yaml',
default=True)
config = _root(source)
config.config_dir = lambda: '/config/path'
valid = config['foo'].get(confuse.Filename())
Expand Down

0 comments on commit fd0001c

Please sign in to comment.