Skip to content

Commit

Permalink
Fix tests on Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fchauvel committed Apr 3, 2019
1 parent b51db92 commit dbd9cf9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ script:
docker run --name tests \
-v /var/run/docker.sock:/var/run/docker.sock \
-t ${DOCKER_USERNAME}/${NAME}:dev \
green -qrfvv tests
green -a -qrfvv tests
- docker cp tests:/camp/.coverage .coverage
- codecov

Expand Down
10 changes: 4 additions & 6 deletions camp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def wrapped_generator(*args, **kwargs):
def wrapped(*args, **kwargs):
with StderrRedirect(destination):
return function(*args, **kwargs)

if isgeneratorfunction(function):
return wrapped_generator
return wrapped

return decorate




class StderrRedirect(object):


def __init__(self, destination=devnull):
self._destination = destination

Expand All @@ -66,5 +66,3 @@ def __exit__(self, ex_type, ex_value, ex_traceback):

# Redirect stderr so it points back towards its original file
dup2(self._memento_fd, self._stderr_fd)


2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ cleanup () {
apt-get autoremove -y >> ${LOG_FILE} 2>&1
rm -rf /var/lib/apt/lists/*

ln -s -f /usr/bin/python2.7 /usr/bin/python
ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python
if [[ "${DEBUG}" == "false" ]]
then
rm -rf ${LOG_FILE}
Expand Down
14 changes: 7 additions & 7 deletions tests/codecs/test_yaml_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from camp.entities.report import SuccessfulTest, FailedTest, ErroneousTest, \
TestSuite, TestReport

from io import BytesIO
from io import BytesIO, StringIO

from unittest import TestCase

Expand Down Expand Up @@ -256,7 +256,7 @@ def test_given_a_component_with_a_realized_variable(self):


def assert_complete(self, text, expectations):
model = self._codec.load_model_from(BytesIO(text))
model = self._codec.load_model_from(BytesIO(text.encode()))

self.assertEqual(0, len(self._codec.warnings))

Expand Down Expand Up @@ -327,7 +327,7 @@ def setUp(self):

def assert_extra_in(self, text, expected):
try :
self._codec.load_model_from(BytesIO(text))
self._codec.load_model_from(BytesIO(text.encode()))
fail("Should have raised an exception!")
except InvalidYAMLModel as error:
self.assertEqual(1, len(error.warnings))
Expand Down Expand Up @@ -591,7 +591,7 @@ def test_with_a_string_as_substitution_targets(self):

def assert_warning(self, text, expected, found, path, warning_count=1):
try:
model = self._codec.load_model_from(BytesIO(text))
model = self._codec.load_model_from(BytesIO(text.encode()))
self.fail("InvalidYAMLModel should have been thrown!")

except InvalidYAMLModel as error:
Expand All @@ -613,7 +613,7 @@ def setUp(self):
self._codec = YAML()

def assert_no_warning_in(self, text):
model = self._codec.load_model_from(BytesIO(text))
model = self._codec.load_model_from(BytesIO(text.encode()))

self.assertEqual(0, len(self._codec.warnings))

Expand Down Expand Up @@ -784,7 +784,7 @@ def test_when_omitting_the_docker_file(self):

def assert_missing(self, text, path, candidates):
try:
model = self._codec.load_model_from(BytesIO(text))
model = self._codec.load_model_from(BytesIO(text.encode()))
self.fail("InvalidYAMLModel should have been thrown!")

except InvalidYAMLModel as error:
Expand All @@ -800,7 +800,7 @@ class TestReportsAreSerialized(TestCase):


def setUp(self):
self._output = BytesIO()
self._output = StringIO()
self._codec = YAML()


Expand Down
2 changes: 1 addition & 1 deletion tests/generate/test_new_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):


def assert_variables_values(self, text, configuration_count, expected_values):
model = self._yaml.load_model_from(BytesIO(text))
model = self._yaml.load_model_from(BytesIO(text.encode()))

self.assertFalse(self._yaml.warnings, "\n".join(str(each) for each in self._yaml.warnings))

Expand Down
10 changes: 4 additions & 6 deletions tests/generate/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

from shutil import rmtree

from tempfile import mkdtemp

from unittest import TestCase


Expand Down Expand Up @@ -107,15 +109,11 @@ def test_orchestrations(self):


def prepare_sample(self, sample):
self._working_directory = self.WORKING_DIRECTORY
if isdir(self._working_directory):
rmtree(self._working_directory)
self._working_directory = join(mkdtemp(prefix="camp_"), "generate")
makedirs(self._working_directory)
with open(join(self._working_directory, "camp.yaml"), "w") as stream:
stream.write(sample)

WORKING_DIRECTORY = "tmp/generate"


def invoke_camp_generate(self):
camp = Camp(YAML(), Z3Problem, Builder())
Expand All @@ -125,7 +123,7 @@ def invoke_camp_generate(self):

def assert_configuration_count_is(self, expected):
generated = []
destination = join(self.WORKING_DIRECTORY, "out")
destination = join(self._working_directory, "out")
for each_file in listdir(destination):
if match(r"config_\d+", each_file):
generated.append(each_file)
Expand Down

0 comments on commit dbd9cf9

Please sign in to comment.