Skip to content

Commit 982e4cb

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Fix tests for windows
Summary: Various things aren't supported on Windows so let's disable them. The only super odd thing here is the preloading tests where we're failing to import asyncio but presumably not sure that's anything we're super concerned about yet. Reviewed By: yoney Differential Revision: D103317852 fbshipit-source-id: 5e329b4536347bf38fcaae9d85fb0537854ca45e
1 parent fdcb273 commit 982e4cb

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

cinderx/PythonLib/test_cinderx/test_immortalize.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# pyre-unsafe
33

4+
import os
45
import unittest
56

67
import cinderx
@@ -14,12 +15,14 @@ def test_default_not_immortal(self) -> None:
1415
obj = []
1516
self.assertFalse(cinderx.is_immortal(obj))
1617

18+
@unittest.skipUnless(hasattr(os, "fork"), "fork not available on Windows")
1719
@run_in_subprocess
1820
def test_is_immortal(self) -> None:
1921
obj = []
2022
cinderx.immortalize_heap()
2123
self.assertTrue(cinderx.is_immortal(obj))
2224

25+
@unittest.skipUnless(hasattr(os, "fork"), "fork not available on Windows")
2326
@run_in_subprocess
2427
def test_post_immortalize(self) -> None:
2528
cinderx.immortalize_heap()

cinderx/PythonLib/test_cinderx/test_jit_global_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# pyre-unsafe
66

77
import builtins
8+
import os
89
import unittest
910
from textwrap import dedent
1011

@@ -141,6 +142,7 @@ def _test_unwatch_builtins(self):
141142
# pyrefly: ignore [unsupported-operation]
142143
builtins.__dict__[42] = 42
143144

145+
@unittest.skipUnless(hasattr(os, "fork"), "fork not available on Windows")
144146
@run_in_subprocess
145147
def test_unwatch_builtins(self):
146148
try:

cinderx/PythonLib/test_cinderx/test_jit_perf_map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
class PerfMapTests(unittest.TestCase):
19+
@unittest.skipUnless(hasattr(os, "fork"), "fork not available on Windows")
1920
@skip_unless_jit("Runs a subprocess with the JIT enabled")
2021
def test_forked_pid_map(self) -> None:
2122
helper_file = os.path.join(

cinderx/PythonLib/test_cinderx/test_jit_preload.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def test_func_destroyed_during_preload(self) -> None:
102102
"""
103103
self.assertEqual(proc.stdout, expected_stdout)
104104

105+
@unittest.skipIf(
106+
sys.platform == "win32", "asyncio is failing to load in subprocess on Windows"
107+
)
105108
def test_preload_error(self) -> None:
106109
# don't include jit/no-jit in this matrix, decide it based on whether
107110
# overall test run is jit or no-jit; this avoids the confusion of jit
@@ -146,6 +149,9 @@ def test_preload_error(self) -> None:
146149
self.assertEqual(proc.returncode, 1, proc.stderr)
147150
self.assertIn(b"RuntimeError: boom\n", proc.stderr)
148151

152+
@unittest.skipIf(
153+
sys.platform == "win32", "asyncio is failing to load in subprocess on Windows"
154+
)
149155
def test_error_preloading_inlined(self) -> None:
150156
root = os.path.join(os.path.dirname(__file__), "data/error_preloading_inlined")
151157
jitlist = os.path.join(root, "jitlist.txt")

cinderx/PythonLib/test_cinderx/test_jitlist.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_batch_compile_nested_func(self) -> None:
177177
env=subprocess_env(),
178178
)
179179
self.assertEqual(proc.returncode, 0, proc.stderr)
180-
self.assertEqual(b"42\n", proc.stdout, proc.stdout)
180+
self.assertEqual(b"42", proc.stdout.strip(), proc.stdout)
181181

182182
def test_precompile_all(self) -> None:
183183
# Has to be run under a separate process because precompile_all will mess up the
@@ -220,10 +220,11 @@ def victim() -> None:
220220

221221
entry = f"{victim.__module__}:{victim.__qualname__}".replace("victim", "func")
222222

223-
with tempfile.NamedTemporaryFile("w+") as jit_list_file:
224-
jit_list_file.write(entry)
225-
jit_list_file.flush()
226-
cinderx.jit.read_jit_list(jit_list_file.name)
223+
with tempfile.TemporaryDirectory() as tmp:
224+
jit_list_path = os.path.join(tmp, "jitlist.txt")
225+
with open(jit_list_path, "w") as f:
226+
f.write(entry)
227+
cinderx.jit.read_jit_list(jit_list_path)
227228

228229
def func() -> int:
229230
return 35
@@ -250,10 +251,11 @@ def test_read_jit_list_parse_error(self) -> None:
250251
with self.assertRaisesRegex(
251252
RuntimeError, r"Error while parsing line \d+ in JIT list file"
252253
):
253-
with tempfile.NamedTemporaryFile("w+") as jit_list_file:
254-
jit_list_file.write("OH NO")
255-
jit_list_file.flush()
256-
cinderx.jit.read_jit_list(jit_list_file.name)
254+
with tempfile.TemporaryDirectory() as tmp:
255+
jit_list_path = os.path.join(tmp, "jitlist.txt")
256+
with open(jit_list_path, "w") as f:
257+
f.write("OH NO")
258+
cinderx.jit.read_jit_list(jit_list_path)
257259

258260
def test_precompile_all_bad_args(self) -> None:
259261
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)