From fc47e3d5efec8e5675a73c71ec87e16a9bf706fe Mon Sep 17 00:00:00 2001 From: Mark Seaborn Date: Mon, 3 Nov 2008 20:03:18 +0000 Subject: [PATCH] Refactor tests to use the Selections object instead of the Policy object --- tests/testendtoend.py | 80 +++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/tests/testendtoend.py b/tests/testendtoend.py index d638d88..e4eabd8 100644 --- a/tests/testendtoend.py +++ b/tests/testendtoend.py @@ -24,9 +24,11 @@ def manifest_for_dir(dir): return algorithm.getID(digest) -def command_for_policy(policy): - selns = selections.Selections(policy) - return run.get_executable_for_selections(selns) +def selections_for_feed(feed_file): + policy = autopolicy.AutoPolicy( + feed_file, download_only=True, dry_run=False) + policy.download_and_execute([]) + return selections.Selections(policy) class FileTreeWriter(object): @@ -56,10 +58,10 @@ class TestEndToEnd(BaseTest): """ % (manifest_for_dir(temp_dir), tar_file, os.path.getsize(tar_file)) - def _check_output(self, policy, expected_output): + def _check_output(self, selns, expected_output): env = {} - run.add_env_bindings(env, selections.Selections(policy)) - cmd_path = command_for_policy(policy) + run.add_env_bindings(env, selns) + cmd_path = run.get_executable_for_selections(selns) proc = subprocess.Popen([cmd_path], env=env, stdout=subprocess.PIPE) stdout, stderr = proc.communicate() self.assertEquals(proc.wait(), 0) @@ -79,10 +81,8 @@ echo Hello world! """ % self._make_archive(tree)) - policy = autopolicy.AutoPolicy( - feed_file, download_only=True, dry_run=False) - policy.download_and_execute([]) - self._check_output(policy, "Hello world!\n") + selns = selections_for_feed(feed_file) + self._check_output(selns, "Hello world!\n") def test_module_with_dependency(self): library_tree = FileTreeWriter([("share/useful", "useful-contents\n")]) @@ -113,13 +113,11 @@ cat $LIBFOO/share/useful """ % (self._make_archive(main_tree), library_feed)) - policy = autopolicy.AutoPolicy( - main_feed, download_only=True, dry_run=False) - policy.download_and_execute([]) + selns = selections_for_feed(main_feed) env = {} - run.add_env_bindings(env, selections.Selections(policy)) + run.add_env_bindings(env, selns) self.assertEquals(env.keys(), ["LIBFOO"]) - self._check_output(policy, "Got:\nuseful-contents\n") + self._check_output(selns, "Got:\nuseful-contents\n") def test_self_environment_binding(self): tree = FileTreeWriter([("share/useful", "useful-contents\n"), @@ -138,13 +136,11 @@ cat $MY_DATA_DIR/share/useful """ % self._make_archive(tree)) - policy = autopolicy.AutoPolicy( - feed_file, download_only=True, dry_run=False) - policy.download_and_execute([]) + selns = selections_for_feed(feed_file) env = {} - run.add_env_bindings(env, selections.Selections(policy)) + run.add_env_bindings(env, selns) self.assertEquals(env.keys(), ["MY_DATA_DIR"]) - self._check_output(policy, "Got:\nuseful-contents\n") + self._check_output(selns, "Got:\nuseful-contents\n") def test_module_with_substitution_dependency(self): library_tree = FileTreeWriter([("share/useful", "useful-contents\n")]) @@ -175,16 +171,14 @@ cat MAGIC_EMBEDDED_STRING_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/share/useful """ % (self._make_archive(main_tree), library_feed)) - policy = autopolicy.AutoPolicy( - main_feed, download_only=True, dry_run=False) - policy.download_and_execute([]) + selns = selections_for_feed(main_feed) env = {} - run.add_env_bindings(env, selections.Selections(policy)) + run.add_env_bindings(env, selns) self.assertEquals(env.keys(), []) - self._check_output(policy, "Got:\nuseful-contents\n") + self._check_output(selns, "Got:\nuseful-contents\n") # Check that rewritten copies are cached. - self.assertEquals(command_for_policy(policy), - command_for_policy(policy)) + self.assertEquals(run.get_executable_for_selections(selns), + run.get_executable_for_selections(selns)) def test_self_reference_substitution(self): tree = FileTreeWriter([("share/useful", "useful-contents\n"), @@ -203,16 +197,14 @@ cat MAGIC_EMBEDDED_STRING_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/share/useful """ % self._make_archive(tree)) - policy = autopolicy.AutoPolicy( - feed_file, download_only=True, dry_run=False) - policy.download_and_execute([]) + selns = selections_for_feed(feed_file) env = {} - run.add_env_bindings(env, selections.Selections(policy)) + run.add_env_bindings(env, selns) self.assertEquals(env.keys(), []) - self._check_output(policy, "Got:\nuseful-contents\n") + self._check_output(selns, "Got:\nuseful-contents\n") # Check that rewritten copies are cached. - self.assertEquals(command_for_policy(policy), - command_for_policy(policy)) + self.assertEquals(run.get_executable_for_selections(selns), + run.get_executable_for_selections(selns)) def test_fixed_length_substitution_in_dependency(self): original = "MAGIC_EMBEDDED_STRING_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -230,10 +222,8 @@ echo -n MAGIC_EMBEDDED_STRING_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX """ % self._make_archive(tree)) - policy = autopolicy.AutoPolicy( - feed_file, download_only=True, dry_run=False) - policy.download_and_execute([]) - cmd_path = command_for_policy(policy) + selns = selections_for_feed(feed_file) + cmd_path = run.get_executable_for_selections(selns) proc = subprocess.Popen([cmd_path], stdout=subprocess.PIPE) stdout, stderr = proc.communicate() self.assertEquals(proc.wait(), 0) @@ -269,10 +259,8 @@ exit """ % (self._make_archive(main_tree), library_feed)) - policy = autopolicy.AutoPolicy( - main_feed, download_only=True, dry_run=False) - policy.download_and_execute([]) - cmd_path = command_for_policy(policy) + selns = selections_for_feed(main_feed) + cmd_path = run.get_executable_for_selections(selns) proc = subprocess.Popen([cmd_path], stdout=subprocess.PIPE) stdout, stderr = proc.communicate() self.assertEquals(proc.wait(), 0) @@ -322,12 +310,10 @@ exit """ % (self._make_archive(FileTreeWriter([("bin/main", "")])), library_feed)) - policy = autopolicy.AutoPolicy( - main_feed, download_only=True, dry_run=False) - policy.download_and_execute([]) + selns = selections_for_feed(main_feed) env = {} - run.add_env_bindings(env, selections.Selections(policy)) - command_for_policy(policy) + run.add_env_bindings(env, selns) + run.get_executable_for_selections(selns) suite = unittest.makeSuite(TestEndToEnd) -- 2.11.4.GIT