Merge "Check that the argument is in fact a directory"

This commit is contained in:
Jenkins 2016-05-30 06:00:57 +00:00 committed by Gerrit Code Review
commit 5b3477502c
3 changed files with 23 additions and 2 deletions

View File

@ -263,6 +263,9 @@ def main(argv=None, stdout=None, _worker=None):
if len(args) != 1: if len(args) != 1:
print("Must specify directory to update") print("Must specify directory to update")
raise Exception("Must specify one and only one directory to update.") raise Exception("Must specify one and only one directory to update.")
if not os.path.isdir(args[0]):
print("%s is not a directory." % (args[0]))
raise Exception("%s is not a directory." % (args[0]))
if stdout is None: if stdout is None:
stdout = sys.stdout stdout = sys.stdout
if _worker is None: if _worker is None:

View File

@ -19,6 +19,7 @@ import sys
import textwrap import textwrap
import fixtures import fixtures
import mock
import testscenarios import testscenarios
import testtools import testtools
from testtools import matchers from testtools import matchers
@ -216,7 +217,8 @@ Syncing setup.py
class TestMain(testtools.TestCase): class TestMain(testtools.TestCase):
def test_smoke(self): @mock.patch('os.path.isdir', return_value=True)
def test_smoke(self, mock_isdir):
def check_params( def check_params(
root, source, suffix, softupdate, hacking, stdout, verbose, root, source, suffix, softupdate, hacking, stdout, verbose,
non_std_reqs): non_std_reqs):
@ -232,14 +234,29 @@ class TestMain(testtools.TestCase):
with fixtures.EnvironmentVariable('NON_STANDARD_REQS', '1'): with fixtures.EnvironmentVariable('NON_STANDARD_REQS', '1'):
update.main( update.main(
['--source', '/dev/null', '/dev/zero'], _worker=check_params) ['--source', '/dev/null', '/dev/zero'], _worker=check_params)
self.expectThat(mock_isdir.called, matchers.Equals(True))
def test_suffix(self): @mock.patch('os.path.isdir', return_value=True)
def test_suffix(self, mock_isdir):
def check_params( def check_params(
root, source, suffix, softupdate, hacking, stdout, verbose, root, source, suffix, softupdate, hacking, stdout, verbose,
non_std_reqs): non_std_reqs):
self.expectThat(suffix, matchers.Equals('global')) self.expectThat(suffix, matchers.Equals('global'))
update.main(['-o', 'global', '/dev/zero'], _worker=check_params) update.main(['-o', 'global', '/dev/zero'], _worker=check_params)
self.expectThat(mock_isdir.called, matchers.Equals(True))
def test_isdirectory(self):
def never_called(
root, source, suffix, softupdate, hacking, stdout, verbose,
non_std_reqs):
self.expectThat(False, matchers.Equals(True),
message=("update.main() should riase an "
"excpetion before getting here"))
with testtools.ExpectedException(Exception,
"/dev/zero is not a directory"):
update.main(['/dev/zero'], _worker=never_called)
class TestSyncRequirementsFile(testtools.TestCase): class TestSyncRequirementsFile(testtools.TestCase):

View File

@ -10,6 +10,7 @@ testscenarios>=0.4 # Apache-2.0/BSD
testtools>=1.4.0 # MIT testtools>=1.4.0 # MIT
virtualenv # MIT virtualenv # MIT
setuptools>=16.0 # PSF/ZPL setuptools>=16.0 # PSF/ZPL
mock>=1.2 # BSD
# this is required for the docs build jobs # this is required for the docs build jobs
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD