Skip to content

Commit c68859a

Browse files
committedJun 21, 2022
test(hansbug): try fix the problem when testing win32 wheel
1 parent 1d4cd4a commit c68859a

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed
 

‎pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ skip = ["pp*"] # Do not build for PyPy
1212
[tool.cibuildwheel.windows]
1313
archs = ["x86", 'AMD64']
1414
before-test = [# Unittest for windows
15-
"pip install -r \"{project}/requirements-test.txt\"",
15+
"pip install -r \"{project}\\requirements-test-win.txt\"",
1616
]
1717
test-command = [
18-
"xcopy /e /i \"{project}/test\" test",
19-
"copy \"{project}/pytest.ini\" pytest.ini",
18+
"xcopy /e /i \"{project}\\test\" test",
19+
"copy \"{project}\\pytest.ini\" pytest.ini",
2020
"pytest test -sv -m unittest --log-level=DEBUG",
2121
"rmdir /s /q test",
2222
]

‎requirements-test-win.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
coverage>=5
2+
mock>=4.0.3
3+
flake8~=3.5
4+
pytest~=6.2.5
5+
pytest-cov~=3.0.0
6+
pytest-mock~=3.6.1
7+
pytest-xdist>=1.34.0
8+
pytest-rerunfailures~=10.2
9+
pytest-timeout~=2.0.2
10+
pytest-benchmark~=3.4.0
11+
testtools>=2
12+
hbutils>=0.6.13
13+
setuptools<=59.5.0
14+
numpy>=1.10
15+
easydict>=1.7,<2
+22-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1+
import unittest
2+
from functools import lru_cache
3+
from typing import Optional
4+
5+
from hbutils.testing import vpip
6+
7+
try:
8+
import torch
9+
except ImportError:
10+
torch = None
11+
112
import pytest
2-
import torch
313

414
from treevalue import TreeValue, func_treelize, FastTreeValue
515

6-
_TREE_DATA_1 = {'a': torch.randn(2, 3), 'x': {'c': torch.randn(3, 4)}}
7-
_TREE_1 = FastTreeValue(_TREE_DATA_1)
16+
17+
@lru_cache()
18+
def _get_tree() -> Optional[FastTreeValue]:
19+
if torch is not None:
20+
_TREE_DATA_1 = {'a': torch.randn(2, 3), 'x': {'c': torch.randn(3, 4)}}
21+
return FastTreeValue(_TREE_DATA_1)
22+
else:
23+
return None
824

925

1026
@pytest.mark.benchmark(group='treevalue_dynamic')
27+
@unittest.skipUnless(vpip('torch') >= '1.1.0', 'Torch>=1.1.0 only')
1128
class TestTreeGeneralBenchmark:
1229
def test_dynamic_execute(self, benchmark):
1330
def sin(t):
1431
return t.sin()
1532

16-
return benchmark(sin, _TREE_1)
33+
return benchmark(sin, _get_tree())
1734

1835
def test_static_execute(self, benchmark):
1936
sinf = func_treelize(return_type=TreeValue)(torch.sin)
2037

2138
def sin(t):
2239
return sinf(t)
2340

24-
return benchmark(sin, _TREE_1)
41+
return benchmark(sin, _get_tree())

‎test/tree/general/test_tensor.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
import unittest
2+
13
import pytest
2-
import torch
4+
from hbutils.testing import vpip
5+
6+
try:
7+
import torch
8+
except ImportError:
9+
torch = None
310

411
from treevalue.tree import func_treelize, FastTreeValue
512

613

714
@pytest.mark.unittest
15+
@unittest.skipUnless(vpip('torch') >= '1.1.0', 'Torch>=1.1.0 only')
816
def test_for_torch_support():
917
sin = func_treelize()(torch.sin)
1018
cos = func_treelize()(torch.cos) # the same sin function

0 commit comments

Comments
 (0)