383
378
parser.parse_args(cmd_line)
385
380
def test_warns_on_dirty_logs(self):
386
with warnings.catch_warnings(record=True) as warned:
387
with temp_dir() as log_dir:
388
open(os.path.join(log_dir, "existing.log"), "w").close()
389
cmd_line = ['local', '/a/juju', log_dir, 'testtest']
390
parser = add_basic_testing_arguments(ArgumentParser())
391
parser.parse_args(cmd_line)
392
self.assertEqual(len(warned), 1)
393
self.assertRegexpMatches(
394
str(warned[0].message),
395
r"^Directory '.*' has existing contents.$")
396
self.assertEqual("", self.log_stream.getvalue())
398
def test_no_warn_on_empty_logs(self):
399
"""Special case a file named 'empty' doesn't make log dir dirty"""
400
with warnings.catch_warnings(record=True) as warned:
401
with temp_dir() as log_dir:
402
open(os.path.join(log_dir, "empty"), "w").close()
403
cmd_line = ['local', '/a/juju', log_dir, 'testtest']
404
parser = add_basic_testing_arguments(ArgumentParser())
405
parser.parse_args(cmd_line)
406
self.assertEqual(warned, [])
407
self.assertEqual("", self.log_stream.getvalue())
381
with temp_dir() as log_dir:
382
open(os.path.join(log_dir, "existing.log"), "w").close()
383
cmd_line = ['local', '/a/juju', log_dir, 'testtest']
384
parser = add_basic_testing_arguments(ArgumentParser())
385
parser.parse_args(cmd_line)
386
self.assertRegexpMatches(
387
self.log_stream.getvalue(),
388
r"^WARNING Directory '.*' has existing contents.$")
409
390
def test_debug(self):
410
391
cmd_line = ['local', '/foo/juju', '/tmp/logs', 'testtest', '--debug']
569
550
self.assertTrue(os.path.exists(d))
570
551
self.assertTrue(os.path.exists(os.path.join(d, "a-file")))
571
552
self.assertFalse(os.path.exists(p))
574
class TestLocalCharm(TestCase):
576
def test_make_local_charm_1x(self):
578
path = local_charm_path(charm, '1.25.0')
579
self.assertEqual(path, 'local:mysql')
581
def test_make_local_charm_1x_series(self):
583
path = local_charm_path(charm, '1.25.0', series='trusty')
584
self.assertEqual(path, 'local:trusty/mysql')
586
def test_make_local_charm_2x(self):
588
path = local_charm_path(charm, '2.0.0', repository='/tmp/charms')
589
self.assertEqual(path, '/tmp/charms/mysql')
591
def test_make_local_charm_2x_os_env(self):
593
with temp_os_env('JUJU_REPOSITORY', '/home/foo/repository'):
594
path = local_charm_path(charm, '2.0.0')
595
self.assertEqual(path, '/home/foo/repository/charms/mysql')
597
def test_make_local_charm_2x_win(self):
599
with temp_os_env('JUJU_REPOSITORY', '/home/foo/repository'):
600
path = local_charm_path(charm, '2.0.0', platform='win')
601
self.assertEqual(path, '/home/foo/repository/charms-win/mysql')
603
def test_make_local_charm_2x_centos(self):
605
with temp_os_env('JUJU_REPOSITORY', '/home/foo/repository'):
606
path = local_charm_path(charm, '2.0.0', platform='centos')
607
self.assertEqual(path, '/home/foo/repository/charms-centos/mysql')