def test_stdout(self): stdout = io.StringIO() root = self.useFixture(fixtures.TempDir()).path project = {'root': root} actions = [update.StdOut(u'fred\n')] update._write_project(project, actions, stdout, True) self.expectThat(stdout.getvalue(), matchers.Equals('fred\n'))
def test_bad_action(self): root = self.useFixture(fixtures.TempDir()).path stdout = io.StringIO() project = {'root': root} actions = [('foo', 'bar')] with testtools.ExpectedException(Exception): update._write_project(project, actions, stdout, True)
def test_non_verbose(self): stdout = io.StringIO() root = self.useFixture(fixtures.TempDir()).path project = {'root': root} actions = [update.Verbose(u'fred')] update._write_project(project, actions, stdout, False) self.expectThat(stdout.getvalue(), matchers.Equals(''))
def test_verbose_output(self): actions = update._process_project( common.project_project, common.global_reqs, None, None, None, False) capture = StringIO.StringIO() update._write_project( common.project_project, actions, capture, True, True) expected = ("""Syncing %(project)s/requirements.txt Version change for: greenlet, SQLAlchemy, eventlet, PasteDeploy, routes, WebOb, wsgiref, boto, kombu, pycrypto, python-swiftclient, lxml, jsonschema, python-keystoneclient\n""" # noqa """Updated %(project)s/requirements.txt: greenlet>=0.3.1 -> greenlet>=0.3.2 SQLAlchemy>=0.7.8,<=0.7.99 -> SQLAlchemy>=0.7,<=0.7.99 eventlet>=0.9.12 -> eventlet>=0.12.0 PasteDeploy -> PasteDeploy>=1.5.0 routes -> Routes>=1.12.3 WebOb>=1.2 -> WebOb>=1.2.3,<1.3 wsgiref -> wsgiref>=0.1.2 boto -> boto>=2.4.0 kombu>2.4.7 -> kombu>=2.4.8 pycrypto>=2.1.0alpha1 -> pycrypto>=2.6 python-swiftclient>=1.2,<2 -> python-swiftclient>=1.2 lxml -> lxml>=2.3 jsonschema -> jsonschema>=1.0.0,!=1.4.0,<2 python-keystoneclient>=0.2.0 -> python-keystoneclient>=0.4.1 Syncing %(project)s/test-requirements.txt Version change for: mox, mox3, testrepository, testtools Updated %(project)s/test-requirements.txt: mox==0.5.3 -> mox>=0.5.3 mox3==0.7.3 -> mox3>=0.7.0 testrepository>=0.0.13 -> testrepository>=0.0.17 testtools>=0.9.27 -> testtools>=0.9.32 Syncing setup.py """) % dict(project=common.project_project['root']) self.assertEqual(expected, capture.getvalue())
def test_errors(self): stdout = io.StringIO() root = self.useFixture(fixtures.TempDir()).path project = {'root': root} actions = [update.Error(u'fred')] with testtools.ExpectedException(Exception): update._write_project(project, actions, stdout, True) self.expectThat(stdout.getvalue(), matchers.Equals('fred\n'))
def test_smoke(self): stdout = io.StringIO() root = self.useFixture(fixtures.TempDir()).path project = {'root': root} actions = [ update.File('foo', '123\n'), update.File('bar', '456\n'), update.Verbose(u'fred')] update._write_project(project, actions, stdout, True) foo = open(root + '/foo', 'rt').read() self.expectThat(foo, matchers.Equals('123\n')) bar = open(root + '/bar', 'rt').read() self.expectThat(bar, matchers.Equals('456\n')) self.expectThat(stdout.getvalue(), matchers.Equals('fred\n'))