Exemplo n.º 1
0
 def test_temp_dir_parent(self):
     with temp_dir() as p:
         with temp_dir(parent=p) as d:
             self.assertTrue(os.path.isdir(d))
             self.assertEqual(p, os.path.dirname(d))
         self.assertFalse(os.path.exists(d))
     self.assertFalse(os.path.exists(p))
Exemplo n.º 2
0
 def test_temp_dir_parent(self):
     with temp_dir() as p:
         with temp_dir(parent=p) as d:
             self.assertTrue(os.path.isdir(d))
             self.assertEqual(p, os.path.dirname(d))
         self.assertFalse(os.path.exists(d))
     self.assertFalse(os.path.exists(p))
Exemplo n.º 3
0
 def test_temp_dir_keep(self):
     with temp_dir() as p:
         with temp_dir(parent=p, keep=True) as d:
             self.assertTrue(os.path.isdir(d))
             open(os.path.join(d, "a-file"), "w").close()
         self.assertTrue(os.path.exists(d))
         self.assertTrue(os.path.exists(os.path.join(d, "a-file")))
     self.assertFalse(os.path.exists(p))
Exemplo n.º 4
0
 def test_temp_dir_keep(self):
     with temp_dir() as p:
         with temp_dir(parent=p, keep=True) as d:
             self.assertTrue(os.path.isdir(d))
             open(os.path.join(d, "a-file"), "w").close()
         self.assertTrue(os.path.exists(d))
         self.assertTrue(os.path.exists(os.path.join(d, "a-file")))
     self.assertFalse(os.path.exists(p))
Exemplo n.º 5
0
 def test_ignore_older_revision_build(self):
     with temp_dir() as root:
         path_1234 = make_candidate_dir(
             root, '1234-artifacts', 'mybranch', '1234')
         make_candidate_dir(root, '1233', 'mybranch', '1233')
         self.assertEqual(find_latest_branch_candidates(root), [
             (path_1234, 1234)])
Exemplo n.º 6
0
 def test_ignore_older_revision_build(self):
     with temp_dir() as root:
         path_1234 = make_candidate_dir(root, '1234-artifacts', 'mybranch',
                                        '1234')
         make_candidate_dir(root, '1233', 'mybranch', '1233')
         self.assertEqual(find_latest_branch_candidates(root),
                          [(path_1234, 1234)])
Exemplo n.º 7
0
 def test__find_candidates_artifacts_enabled(self):
     with temp_dir() as root:
         make_candidate_dir(root, 'master-artifacts')
         make_candidate_dir(root, '1.25')
         candidate = os.path.join(root, 'candidate', 'master-artifacts')
         self.assertEqual(list(_find_candidates(root, artifacts=True)), [
             (candidate, os.path.join(candidate, 'buildvars.json'))])
Exemplo n.º 8
0
 def test_find_candidates_find_all(self):
     with temp_dir() as root:
         a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
         master_path = make_candidate_dir(root, '1.23', modified=a_week_ago)
         master_path_2 = make_candidate_dir(root, '1.24')
         self.assertItemsEqual(list(find_candidates(root)), [master_path_2])
         self.assertItemsEqual(list(find_candidates(root, find_all=True)),
                               [master_path, master_path_2])
Exemplo n.º 9
0
 def test__find_candidates_artifacts_enabled(self):
     with temp_dir() as root:
         make_candidate_dir(root, 'master-artifacts')
         make_candidate_dir(root, '1.25')
         candidate = os.path.join(root, 'candidate', 'master-artifacts')
         self.assertEqual(
             list(_find_candidates(root, artifacts=True)),
             [(candidate, os.path.join(candidate, 'buildvars.json'))])
Exemplo n.º 10
0
 def test_find_candidates_find_all(self):
     with temp_dir() as root:
         a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
         master_path = make_candidate_dir(root, '1.23', modified=a_week_ago)
         master_path_2 = make_candidate_dir(root, '1.24')
         self.assertItemsEqual(list(find_candidates(root)), [master_path_2])
         self.assertItemsEqual(list(find_candidates(root, find_all=True)),
                               [master_path, master_path_2])
Exemplo n.º 11
0
 def test_include_older_revision_build_different_branch(self):
     with temp_dir() as root:
         path_1234 = make_candidate_dir(root, '1234-artifacts',
                                        'branch_foo', '1234')
         path_1233 = make_candidate_dir(root, '1233-artifacts',
                                        'branch_bar', '1233')
         self.assertItemsEqual(find_latest_branch_candidates(root),
                               [(path_1233, 1233), (path_1234, 1234)])
Exemplo n.º 12
0
 def test_include_older_revision_build_different_branch(self):
     with temp_dir() as root:
         path_1234 = make_candidate_dir(
             root, '1234-artifacts', 'branch_foo', '1234')
         path_1233 = make_candidate_dir(
             root, '1233-artifacts', 'branch_bar', '1233')
         self.assertItemsEqual(
             find_latest_branch_candidates(root), [
                 (path_1233, 1233), (path_1234, 1234)])
Exemplo n.º 13
0
def client_and_plan():
    cur_client = fake_juju_client()
    cur_client.bootstrap()
    with patch('hammer_time.hammer_time.client_for_existing',
               return_value=cur_client,
               autospec=True) as cfe_mock:
        with temp_dir() as plan_dir:
            plan_file = os.path.join(plan_dir, 'asdf.yaml')
            yield (cur_client, cfe_mock, plan_file)
Exemplo n.º 14
0
 def test_no_warn_on_empty_logs(self):
     """Special case a file named 'empty' doesn't make log dir dirty"""
     with warnings.catch_warnings(record=True) as warned:
         with temp_dir() as log_dir:
             open(os.path.join(log_dir, "empty"), "w").close()
             cmd_line = ['local', '/a/juju', log_dir, 'testtest']
             parser = add_basic_testing_arguments(ArgumentParser())
             parser.parse_args(cmd_line)
         self.assertEqual(warned, [])
     self.assertEqual("", self.log_stream.getvalue())
Exemplo n.º 15
0
 def test_no_warn_on_empty_logs(self):
     """Special case a file named 'empty' doesn't make log dir dirty"""
     with warnings.catch_warnings(record=True) as warned:
         with temp_dir() as log_dir:
             open(os.path.join(log_dir, "empty"), "w").close()
             cmd_line = ['local', '/a/juju', log_dir, 'testtest']
             parser = add_basic_testing_arguments(ArgumentParser())
             parser.parse_args(cmd_line)
         self.assertEqual(warned, [])
     self.assertEqual("", self.log_stream.getvalue())
Exemplo n.º 16
0
 def test_warns_on_dirty_logs(self):
     with warnings.catch_warnings(record=True) as warned:
         with temp_dir() as log_dir:
             open(os.path.join(log_dir, "existing.log"), "w").close()
             cmd_line = ['local', '/a/juju', log_dir, 'testtest']
             parser = add_basic_testing_arguments(ArgumentParser())
             parser.parse_args(cmd_line)
         self.assertEqual(len(warned), 1)
         self.assertRegexpMatches(
             str(warned[0].message),
             r"^Directory '.*' has existing contents.$")
     self.assertEqual("", self.log_stream.getvalue())
Exemplo n.º 17
0
 def test_warns_on_dirty_logs(self):
     with warnings.catch_warnings(record=True) as warned:
         with temp_dir() as log_dir:
             open(os.path.join(log_dir, "existing.log"), "w").close()
             cmd_line = ['local', '/a/juju', log_dir, 'testtest']
             parser = add_basic_testing_arguments(ArgumentParser())
             parser.parse_args(cmd_line)
         self.assertEqual(len(warned), 1)
         self.assertRegexpMatches(
             str(warned[0].message),
             r"^Directory '.*' has existing contents.$")
     self.assertEqual("", self.log_stream.getvalue())
Exemplo n.º 18
0
 def test_find_candidates_old_buildvars(self):
     with temp_dir() as root:
         a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
         make_candidate_dir(root, 'master', modified=a_week_ago)
         self.assertEqual(list(find_candidates(root)), [])
Exemplo n.º 19
0
 def test_find_latest_branch_candidates(self):
     with temp_dir() as root:
         master_path = make_candidate_dir(root, 'master-artifacts')
         self.assertEqual(find_latest_branch_candidates(root),
                          [(master_path, 1234)])
Exemplo n.º 20
0
 def test_find_latest_branch_candidates(self):
     with temp_dir() as root:
         master_path = make_candidate_dir(root, 'master-artifacts')
         self.assertEqual(find_latest_branch_candidates(root),
                          [(master_path, 1234)])
Exemplo n.º 21
0
 def test_find_candidates_artifacts(self):
     with temp_dir() as root:
         make_candidate_dir(root, 'master-artifacts')
         self.assertEqual(list(find_candidates(root)), [])
Exemplo n.º 22
0
 def test_find_candidates(self):
     with temp_dir() as root:
         master_path = make_candidate_dir(root, 'master')
         self.assertEqual(list(find_candidates(root)), [master_path])
Exemplo n.º 23
0
 def test_find_candidates(self):
     with temp_dir() as root:
         master_path = make_candidate_dir(root, 'master')
         self.assertEqual(list(find_candidates(root)), [master_path])
Exemplo n.º 24
0
 def test_temp_dir_contents(self):
     with temp_dir() as d:
         self.assertTrue(os.path.isdir(d))
         open(os.path.join(d, "a-file"), "w").close()
     self.assertFalse(os.path.exists(d))
Exemplo n.º 25
0
 def test_temp_dir(self):
     with temp_dir() as d:
         self.assertTrue(os.path.isdir(d))
     self.assertFalse(os.path.exists(d))
Exemplo n.º 26
0
 def test_find_candidates_old_buildvars(self):
     with temp_dir() as root:
         a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
         make_candidate_dir(root, 'master', modified=a_week_ago)
         self.assertEqual(list(find_candidates(root)), [])
Exemplo n.º 27
0
 def test_find_candidates_artifacts(self):
     with temp_dir() as root:
         make_candidate_dir(root, 'master-artifacts')
         self.assertEqual(list(find_candidates(root)), [])
Exemplo n.º 28
0
 def test_temp_dir(self):
     with temp_dir() as d:
         self.assertTrue(os.path.isdir(d))
     self.assertFalse(os.path.exists(d))
Exemplo n.º 29
0
 def test_temp_dir_contents(self):
     with temp_dir() as d:
         self.assertTrue(os.path.isdir(d))
         open(os.path.join(d, "a-file"), "w").close()
     self.assertFalse(os.path.exists(d))