Skip to content

Commit

Permalink
Fix broken tests in pypy environment removing testfixture package dep…
Browse files Browse the repository at this point in the history
…endency
  • Loading branch information
osantana committed Feb 16, 2016
1 parent 7069c8d commit 4572e28
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,8 @@
1.2.2
=====

- Remove testfixtures requirements (it's broken with pypy)

1.2.1
=====

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
@@ -1,5 +1,4 @@
nose==1.3.7
testfixtures==4.8.0
Sphinx==1.3.1
sphinx-rtd-theme==0.1.8
tox==2.3.1
45 changes: 27 additions & 18 deletions tests/test_filediscover.py
@@ -1,14 +1,15 @@
# coding: utf-8

from __future__ import unicode_literals

import os
import shutil
import tempfile

from testfixtures import TempDirectory

from .base import BaseTestCase
from prettyconf.configuration import ConfigurationDiscovery
from prettyconf.exceptions import InvalidPath
from prettyconf.loaders import IniFileConfigurationLoader
from .base import BaseTestCase


# noinspection PyStatementEffect
Expand All @@ -20,7 +21,7 @@ def setUp(self):
def tearDown(self):
super(ConfigFilesDiscoveryTestCase, self).tearDown()
for tmpdir in self.tmpdirs:
tmpdir.cleanup_all()
shutil.rmtree(tmpdir, ignore_errors=True)

def test_config_file_parsing(self):
self._create_file(self.test_files_path + "/../.env")
Expand Down Expand Up @@ -62,44 +63,52 @@ def test_root_path_should_be_parent_of_starting_path(self):
ConfigurationDiscovery('/foo', root_path='/foo/bar/baz/')

def test_use_configuration_from_root_path_when_no_other_was_found(self):
root_dir = TempDirectory()
root_dir = tempfile.mkdtemp()
self.tmpdirs.append(root_dir)

start_path = root_dir.makedir('some/directories/to/start/looking/for/settings')
test_file = os.path.realpath(os.path.join(root_dir.path, 'settings.ini'))
start_path = os.path.join(root_dir, 'some/directories/to/start/looking/for/settings')
os.makedirs(start_path)

test_file = os.path.realpath(os.path.join(root_dir, 'settings.ini'))
with open(test_file, 'a') as file_:
file_.write('[settings]')
self.files.append(test_file) # Required to removed it at tearDown

discovery = ConfigurationDiscovery(start_path, root_path=root_dir.path)
discovery = ConfigurationDiscovery(start_path, root_path=root_dir)
filenames = [cfg.filename for cfg in discovery.config_files]
self.assertEqual([test_file], filenames)

def test_lookup_should_stop_at_root_path(self):
test_dir = TempDirectory()
test_dir = tempfile.mkdtemp()
self.tmpdirs.append(test_dir) # Cleanup dir at tearDown

start_path = test_dir.makedir('some/dirs/without/config')
start_path = os.path.join(test_dir, 'some/dirs/without/config')
os.makedirs(start_path)

# create a file in the test_dir
test_file = os.path.realpath(os.path.join(test_dir.path, 'settings.ini'))
test_file = os.path.realpath(os.path.join(test_dir, 'settings.ini'))
with open(test_file, 'a') as file_:
file_.write('[settings]')
self.files.append(test_file) # Required to removed it at tearDown

root_dir = os.path.join(test_dir.path, 'some', 'dirs') # No settings here
root_dir = os.path.join(test_dir, 'some', 'dirs') # No settings here

discovery = ConfigurationDiscovery(start_path, root_path=root_dir)
self.assertEqual(discovery.config_files, [])

def test_inifile_discovery_should_ignore_invalid_files_without_raising_exception(self):
root_dir = TempDirectory()
root_dir = tempfile.mkdtemp()
self.tmpdirs.append(root_dir)

cfg_file = root_dir.write(('some', 'strange', 'config.cfg'), '&ˆ%$#$%ˆ&*()(*&ˆ'.encode('utf8'))
root_dir.write(('some', 'config.ini'), '$#%ˆ&*((*&ˆ%'.encode('utf8'))
cfg_dir = os.path.join(root_dir, "some/strange")
os.makedirs(cfg_dir)

discovery = ConfigurationDiscovery(
os.path.realpath(os.path.dirname(cfg_file)), filetypes=(IniFileConfigurationLoader, ))
with open(os.path.join(cfg_dir, "config.cfg"), "wb") as cfg_file:
cfg_file.write('&ˆ%$#$%ˆ&*()(*&ˆ'.encode('utf8'))
self.files.append(cfg_file.name)

self.assertEqual(discovery.config_files, [])
with open(os.path.join(root_dir, "some/config.ini"), "wb") as cfg_file:
cfg_file.write('$#%ˆ&*((*&ˆ%'.encode('utf8'))

discovery = ConfigurationDiscovery(cfg_dir, filetypes=(IniFileConfigurationLoader,))
self.assertEqual(discovery.config_files, [])
21 changes: 7 additions & 14 deletions tests/test_loaders.py
@@ -1,26 +1,19 @@
# coding: utf-8

from __future__ import unicode_literals

from testfixtures import TempDirectory
import tempfile

from prettyconf.exceptions import InvalidConfigurationFile

from .base import BaseTestCase


class IniFileConfigurationLoaderTestCase(BaseTestCase):

def setUp(self):
super(IniFileConfigurationLoaderTestCase, self).setUp()
self.tmp_dir = TempDirectory()

def tearDown(self):
super(IniFileConfigurationLoaderTestCase, self).tearDown()
self.tmp_dir.cleanup_all()

def test_skip_invalid_ini_file(self):
from prettyconf.loaders import IniFileConfigurationLoader

test_file = self.tmp_dir.write('some/strange/config.cfg', '*&ˆ%$#$%ˆ&*('.encode('utf8'))
with self.assertRaises(InvalidConfigurationFile):
IniFileConfigurationLoader(test_file)
with tempfile.NamedTemporaryFile() as temp:
temp.write(u'*&ˆ%$#$%ˆ&*('.encode("utf-8"))

with self.assertRaises(InvalidConfigurationFile):
IniFileConfigurationLoader(temp.name)
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py34, py35
envlist = py27, py34, py35, pypy

[testenv]
commands = python setup.py test
Expand Down

0 comments on commit 4572e28

Please sign in to comment.