diff --git a/eden/cli/test/systemd_test.py b/eden/cli/test/systemd_test.py index 4e295f7d66..d1858961fd 100644 --- a/eden/cli/test/systemd_test.py +++ b/eden/cli/test/systemd_test.py @@ -9,17 +9,11 @@ import pathlib import typing import unittest -import hypothesis -import hypothesis.strategies from eden.cli.systemd import ( SystemdEnvironmentFile, escape_dbus_address, systemd_escape_path, ) -from eden.test_support.hypothesis import fast_hypothesis_test, set_up_hypothesis - - -set_up_hypothesis() class SystemdEscapeTest(unittest.TestCase): @@ -217,31 +211,6 @@ class SystemdEnvironmentFileDumpTest(unittest.TestCase): ): self.dumps(variables) - @fast_hypothesis_test() - @hypothesis.given(hypothesis.strategies.binary()) - def test_arbitrary_variable_value_round_trips_through_dump_and_load( - self, value: bytes - ) -> None: - self.hypothesis_assume_variable_value_is_valid(value) - self.assert_variable_dumps_and_loads(b"var", value) - - @fast_hypothesis_test() - @hypothesis.given(hypothesis.strategies.binary()) - def test_arbitrary_variable_name_round_trips_through_dump_and_load( - self, name: bytes - ) -> None: - self.hypothesis_assume_variable_name_is_valid(name) - self.assert_variable_dumps_and_loads(name, b"value") - - @fast_hypothesis_test() - @hypothesis.given(hypothesis.strategies.binary(), hypothesis.strategies.binary()) - def test_arbitrary_variable_name_and_value_round_trips_through_dump_and_load( - self, name: bytes, value: bytes - ) -> None: - self.hypothesis_assume_variable_name_is_valid(name) - self.hypothesis_assume_variable_value_is_valid(value) - self.assert_variable_dumps_and_loads(name, value) - def assert_variable_dumps_and_loads(self, name: bytes, value: bytes) -> None: self.assertEqual(self.dump_and_load({name: value}).entries, [(name, value)]) @@ -256,21 +225,6 @@ class SystemdEnvironmentFileDumpTest(unittest.TestCase): def loads(self, content: bytes) -> SystemdEnvironmentFile: return SystemdEnvironmentFile.loads(content) - def hypothesis_assume_variable_name_is_valid(self, name: bytes) -> None: - lower_alphabet = b"abcdefghijklmnopqrstuvwxyz" - upper_alphabet = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" - digits = b"0123456789" - allowed_characters = b"".join([b"_", lower_alphabet, upper_alphabet, digits]) - hypothesis.assume(len(name) > 0) - hypothesis.assume(all(c in allowed_characters for c in name)) - hypothesis.assume(name[0] not in digits) - - def hypothesis_assume_variable_value_is_valid(self, value: bytes) -> None: - invalid_control_characters = bytes(range(0, b"\n"[0])) + bytes( - range(b"\n"[0] + 1, b" "[0]) - ) - hypothesis.assume(all(c not in invalid_control_characters for c in value)) - class SystemdEnvironmentFileLoadTest(unittest.TestCase): # TODO(strager): Discard variables whose values are not valid UTF-8. @@ -617,13 +571,6 @@ class SystemdEnvironmentFileLoadTest(unittest.TestCase): self.loads(b"name=hello\x00world").entries, [(b"name", b"hello")] ) - @fast_hypothesis_test() - @hypothesis.given(hypothesis.strategies.binary()) - def test_loading_arbitrary_file_does_not_crash_or_hang( - self, content: bytes - ) -> None: - self.loads(content) - def loads(self, content: bytes) -> SystemdEnvironmentFile: return SystemdEnvironmentFile.loads(content) diff --git a/eden/integration/hypothesis_simple_test.py b/eden/integration/hypothesis_simple_test.py deleted file mode 100644 index 1378b7f7af..0000000000 --- a/eden/integration/hypothesis_simple_test.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This software may be used and distributed according to the terms of the -# GNU General Public License version 2. - -import os -import stat - -import hypothesis -from eden.test_support.hypothesis import FILENAME_STRATEGY - -from .lib import testcase - - -@testcase.eden_repo_test -class HypothesisSimpleTest(testcase.EdenRepoTest): - def populate_repo(self) -> None: - self.repo.write_file("hello", "hola\n") - self.repo.write_file("adir/file", "foo!\n") - self.repo.write_file("bdir/test.sh", "#!/bin/bash\necho test\n", mode=0o755) - self.repo.write_file("bdir/noexec.sh", "#!/bin/bash\necho test\n") - self.repo.symlink("slink", "hello") - self.repo.commit("Initial commit.") - - @hypothesis.given(FILENAME_STRATEGY) - def test_create(self, basename: str) -> None: - filename = os.path.join(self.mount, basename) - - # Ensure that we don't proceed if hypothesis has selected a name that - # conflicts with the names we generated in the repo. - hypothesis.assume(not os.path.exists(filename)) - - with open(filename, "w") as f: - f.write("created\n") - - self.assert_checkout_root_entries( - {".eden", "adir", "bdir", "hello", basename, "slink"} - ) - - with open(filename, "r") as f: - self.assertEqual(f.read(), "created\n") - - st = os.lstat(filename) - self.assertEqual(st.st_size, 8) - self.assertTrue(stat.S_ISREG(st.st_mode)) diff --git a/eden/integration/lib/testcase.py b/eden/integration/lib/testcase.py index 56ecce7672..ad0abf8857 100644 --- a/eden/integration/lib/testcase.py +++ b/eden/integration/lib/testcase.py @@ -35,23 +35,6 @@ from . import edenclient, gitrepo, hgrepo, repobase from .find_executables import FindExe -try: - from eden.test_support.hypothesis import set_up_hypothesis - import hypothesis.internal.detection - - set_up_hypothesis() - - def is_hypothesis_test(test): - return hypothesis.internal.detection.is_hypothesis_test(test) - return False - - -except ImportError: - # Continue even if the hypothesis module is not available - def is_hypothesis_test(test): - return False - - if not FindExe.is_buck_build() or os.environ.get("EDENFS_SUFFIX", "") != "": _build_flavor = "open_source" else: @@ -80,34 +63,6 @@ class EdenTestCase( enable_logview: bool = True - # The current typeshed library claims unittest.TestCase.run() returns a TestCase, - # but it really returns Optional[TestResult]. - # We declare it to return Any here just to make the type checkers happy. - def run(self, result: Optional[unittest.TestResult] = None) -> Any: - """ Some slightly awful magic here to arrange for setUp and - tearDown to be called at the appropriate times when hypothesis - is enabled for a test case. - This can be removed once a future version of hypothesis - ships with support for this baked in. """ - if is_hypothesis_test(getattr(self, self._testMethodName)): - try: - old_setUp = self.setUp - old_tearDown = self.tearDown - self.setUp = lambda: None # type: ignore # (mypy issue 2427) - self.tearDown = lambda: None # type: ignore # (mypy issue 2427) - # pyre-fixme[16]: `EdenTestCase` has no attribute `setup_example`. - self.setup_example = old_setUp - # pyre-fixme[16]: `EdenTestCase` has no attribute `teardown_example`. - self.teardown_example = lambda _: old_tearDown() - return super(EdenTestCase, self).run(result) - finally: - self.setUp = old_setUp # type: ignore # (mypy issue 2427) - self.tearDown = old_tearDown # type: ignore # (mypy issue 2427) - del self.setup_example - del self.teardown_example - else: - return super(EdenTestCase, self).run(result) - def report_time(self, event: str) -> None: """ report_time() is a helper function for logging how long different diff --git a/eden/test_support/hypothesis.py b/eden/test_support/hypothesis.py deleted file mode 100644 index cb2ffbff65..0000000000 --- a/eden/test_support/hypothesis.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This software may be used and distributed according to the terms of the -# GNU General Public License version 2. - -import atexit -import os -import pathlib -import tempfile - -import hypothesis.strategies as st -from eden.test_support.temporary_directory import cleanup_tmp_dir -from hypothesis import HealthCheck, settings -from hypothesis.configuration import hypothesis_home_dir, set_hypothesis_home_dir - - -def is_sandcastle() -> bool: - return "SANDCASTLE" in os.environ - - -def fast_hypothesis_test(): - return settings(max_examples=1000, suppress_health_check=[]) - - -def set_up_hypothesis() -> None: - default_settings = settings( - # Turn off the health checks because setUp/tearDown are too slow - suppress_health_check=[HealthCheck.too_slow], - # Turn off the example database; we don't have a way to persist this - # or share this across runs, so we don't derive any benefit from it at - # this time. - database=None, - ) - - # Configure Hypothesis to run faster when iterating locally - settings.register_profile( - "dev", settings(default_settings, max_examples=5, timeout=0) - ) - # ... and use the defaults (which have more combinations) when running - # on CI, which we want to be more deterministic. - settings.register_profile( - "ci", settings(default_settings, derandomize=True, timeout=120) - ) - - # Use the dev profile by default, but use the ci profile on sandcastle. - settings.load_profile( - "ci" if is_sandcastle() else os.getenv("HYPOTHESIS_PROFILE", "dev") - ) - - # We need to set a global (but non-conflicting) path to store some state - # during hypothesis example runs. We want to avoid putting this state in - # the repo. - set_hypothesis_home_dir(tempfile.mkdtemp(prefix="eden_hypothesis.")) - atexit.register(cleanup_tmp_dir, pathlib.Path(hypothesis_home_dir())) - - -# Some helpers for Hypothesis decorators -FILENAME_STRATEGY = st.text( - st.characters(min_codepoint=1, max_codepoint=1000, blacklist_characters="/:\\"), - min_size=1, -)