Skip to content

Commit

Permalink
Merge pull request #51 from moshez/48-remove-resource-warnings
Browse files Browse the repository at this point in the history
fix resource warnings in tests
  • Loading branch information
moshez committed Sep 9, 2017
2 parents ea5da01 + f8dbe5b commit 3d54376
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ncolony/tests/test_ctllib.py
Expand Up @@ -4,6 +4,7 @@
"""Tests for ncolony.ctllib"""

import argparse
import io
import json
import os
import shutil
Expand All @@ -13,6 +14,11 @@

from ncolony import ctllib

def jsonFrom(fname):
"""Load JSON from a file"""
with io.open(fname, "r", encoding='utf-8') as fp:
return json.loads(fp.read())

class TestArgParsing(unittest.TestCase):

"""Test the argument parser"""
Expand Down Expand Up @@ -129,14 +135,14 @@ def test_main(self):
ctllib.main(argv)
fname, = os.listdir(self.places.messages)
fname = os.path.join(self.places.messages, fname)
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(type='RESTART-ALL'))

def test_add_and_remove(self):
"""Test that add/remove work"""
ctllib.add(self.places, 'hello', cmd='/bin/echo', args=['hello'])
fname = os.path.join(self.places.config, 'hello')
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(args=['/bin/echo', 'hello']))
ctllib.remove(self.places, 'hello')
self.assertFalse(os.path.exists(fname))
Expand All @@ -147,7 +153,7 @@ def test_add_with_env_and_extras(self):
ctllib.add(self.places, 'hello', cmd='/bin/echo',
args=['hello'], env=['world=616'], extras=extras)
fname = os.path.join(self.places.config, 'hello')
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(env={'world': '616'},
goodbye=[1, 2, 3],
args=['/bin/echo', 'hello']))
Expand All @@ -156,22 +162,22 @@ def test_add_with_uid(self):
"""Test that add with optional uid works"""
ctllib.add(self.places, 'hello', cmd='/bin/echo', args=['hello'], uid=1024)
fname = os.path.join(self.places.config, 'hello')
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(uid=1024, args=['/bin/echo', 'hello']))

def test_add_with_gid(self):
"""Test that add with optional gid works"""
ctllib.add(self.places, 'hello', cmd='/bin/echo', args=['hello'], gid=1024)
fname = os.path.join(self.places.config, 'hello')
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(gid=1024, args=['/bin/echo', 'hello']))

def test_restart(self):
"""Test that restart works"""
ctllib.restart(self.places, 'hello')
fname, = os.listdir(self.places.messages)
fname = os.path.join(self.places.messages, fname)
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(type='RESTART', name='hello'))
ctllib.restart(self.places, 'goodbye')
things = (json.loads(open(os.path.join(self.places.messages, fname)).read())
Expand All @@ -189,7 +195,7 @@ def test_restart_all(self):
ctllib.restartAll(self.places)
fname, = os.listdir(self.places.messages)
fname = os.path.join(self.places.messages, fname)
d = json.loads(open(fname).read())
d = jsonFrom(fname)
self.assertEquals(d, dict(type='RESTART-ALL'))

def test_extra_protection(self):
Expand Down

0 comments on commit 3d54376

Please sign in to comment.