Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
ae999e17
T
treevalue
项目概览
OpenDILab开源决策智能平台
/
treevalue
大约 1 年 前同步成功
通知
3
Star
213
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
treevalue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ae999e17
编写于
6月 21, 2022
作者:
HansBug
😆
提交者:
GitHub
6月 21, 2022
1
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #46 from opendilab/test/windows
test(hansbug): add test for windows
上级
ee2a5527
c68859ae
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
143 addition
and
59 deletion
+143
-59
.github/workflows/release.yml
.github/workflows/release.yml
+1
-1
.github/workflows/release_test.yml
.github/workflows/release_test.yml
+1
-1
.github/workflows/test.yml
.github/workflows/test.yml
+4
-4
pyproject.toml
pyproject.toml
+13
-1
requirements-test-win.txt
requirements-test-win.txt
+15
-0
test/entry/cli/test_export.py
test/entry/cli/test_export.py
+22
-11
test/entry/cli/test_graph.py
test/entry/cli/test_graph.py
+34
-16
test/entry/cli/test_version.py
test/entry/cli/test_version.py
+2
-1
test/tree/general/test_general_benchmark.py
test/tree/general/test_general_benchmark.py
+22
-5
test/tree/general/test_tensor.py
test/tree/general/test_tensor.py
+9
-1
test/utils/test_formattree.py
test/utils/test_formattree.py
+19
-12
treevalue/entry/cli/graph.py
treevalue/entry/cli/graph.py
+1
-6
未找到文件。
.github/workflows/release.yml
浏览文件 @
ae999e17
...
...
@@ -58,7 +58,7 @@ jobs:
matrix
:
os
:
-
'
ubuntu-18.04'
#
- 'windows-2019'
-
'
windows-2019'
-
'
macos-10.15'
python
:
-
'
3.6'
...
...
.github/workflows/release_test.yml
浏览文件 @
ae999e17
...
...
@@ -49,7 +49,7 @@ jobs:
matrix
:
os
:
-
'
ubuntu-18.04'
#
- 'windows-2019'
-
'
windows-2019'
-
'
macos-10.15'
python
:
-
'
3.6'
...
...
.github/workflows/test.yml
浏览文件 @
ae999e17
...
...
@@ -18,7 +18,7 @@ jobs:
matrix
:
os
:
-
'
ubuntu-18.04'
#
- 'windows-2019' # need to be fixed, see: https://github.com/opendilab/treevalue/issues/41
-
'
windows-2019'
# need to be fixed, see: https://github.com/opendilab/treevalue/issues/41
-
'
macos-10.15'
python-version
:
-
'
3.6'
...
...
@@ -29,21 +29,21 @@ jobs:
steps
:
-
name
:
Get system version for Linux
if
:
${{
contains(matrix.os, 'ubuntu')
}}
if
:
${{
runner.os == 'Linux'
}}
shell
:
bash
run
:
|
echo "OS_NAME=Linux" >> $GITHUB_ENV
echo "IS_WIN=" >> $GITHUB_ENV
echo "IS_MAC=" >> $GITHUB_ENV
-
name
:
Get system version for Windows
if
:
${{
contains(matrix.os, 'windows')
}}
if
:
${{
runner.os == 'Windows'
}}
shell
:
bash
run
:
|
echo "OS_NAME=Windows" >> $GITHUB_ENV
echo "IS_WIN=1" >> $GITHUB_ENV
echo "IS_MAC=" >> $GITHUB_ENV
-
name
:
Get system version for MacOS
if
:
${{
contains(matrix.os, 'macos')
}}
if
:
${{
runner.os == 'macOS'
}}
shell
:
bash
run
:
|
echo "OS_NAME=MacOS" >> $GITHUB_ENV
...
...
pyproject.toml
浏览文件 @
ae999e17
...
...
@@ -8,11 +8,23 @@ requires = [
[tool.cibuildwheel]
skip
=
["pp*"]
# Do not build for PyPy
## Windows build configuration
[tool.cibuildwheel.windows]
archs
=
[
"x86"
,
'AMD64'
]
before-test
=
[
# Unittest for windows
"pip install -r
\"
{project}
\\
requirements-test-win.txt
\"
"
,
]
test-command
=
[
"xcopy /e /i
\"
{project}
\\
test
\"
test"
,
"copy
\"
{project}
\\
pytest.ini
\"
pytest.ini"
,
"pytest test -sv -m unittest --log-level=DEBUG"
,
"rmdir /s /q test"
,
]
## macOS build configuration
[tool.cibuildwheel.macos]
archs
=
[
"x86_64"
,
"arm64"
]
# Build for x86_64 and arm64
before-test
=
[
# Unittest for
linux
before-test
=
[
# Unittest for
macos
"pip install -r {project}/requirements-test.txt"
,
]
test-command
=
[
...
...
requirements-test-win.txt
0 → 100644
浏览文件 @
ae999e17
coverage>=5
mock>=4.0.3
flake8~=3.5
pytest~=6.2.5
pytest-cov~=3.0.0
pytest-mock~=3.6.1
pytest-xdist>=1.34.0
pytest-rerunfailures~=10.2
pytest-timeout~=2.0.2
pytest-benchmark~=3.4.0
testtools>=2
hbutils>=0.6.13
setuptools<=59.5.0
numpy>=1.10
easydict>=1.7,<2
\ No newline at end of file
test/entry/cli/test_export.py
浏览文件 @
ae999e17
...
...
@@ -30,7 +30,8 @@ class TestEntryCliExport:
with
runner
.
isolated_filesystem
():
result
=
runner
.
invoke
(
treevalue_cli
,
[
'export'
,
'-t'
,
'test.entry.cli.test_export.t1'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
getsize
(
't1.btv'
)
<
240
...
...
@@ -42,7 +43,8 @@ class TestEntryCliExport:
with
runner
.
isolated_filesystem
():
result
=
runner
.
invoke
(
treevalue_cli
,
[
'export'
,
'-t'
,
'test.entry.cli.test_export.*'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
getsize
(
't1.btv'
)
<
240
assert
os
.
path
.
exists
(
't2.btv'
)
...
...
@@ -60,7 +62,8 @@ class TestEntryCliExport:
with
runner
.
isolated_filesystem
():
result
=
runner
.
invoke
(
treevalue_cli
,
[
'export'
,
'-t'
,
'test.entry.cli.test_export.t[23]'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
not
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
exists
(
't2.btv'
)
assert
os
.
path
.
getsize
(
't2.btv'
)
<
290
...
...
@@ -78,7 +81,8 @@ class TestEntryCliExport:
with
pytest
.
warns
(
None
):
result
=
runner
.
invoke
(
treevalue_cli
,
[
'export'
,
'-t'
,
'test.entry.cli.test_export.*'
,
'-r'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
getsize
(
't1.btv'
)
<
2170
assert
os
.
path
.
exists
(
't2.btv'
)
...
...
@@ -98,7 +102,8 @@ class TestEntryCliExport:
result
=
runner
.
invoke
(
treevalue_cli
,
[
'export'
,
'-t'
,
'test.entry.cli.test_export.*'
,
'-r'
,
'-c'
,
'zlib'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
getsize
(
't1.btv'
)
<
2170
assert
os
.
path
.
exists
(
't2.btv'
)
...
...
@@ -119,7 +124,8 @@ class TestEntryCliExport:
result
=
runner
.
invoke
(
treevalue_cli
,
[
'export'
,
'-t'
,
'test.entry.cli.test_export.*'
,
'-c'
,
'gzip'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
getsize
(
't1.btv'
)
<
220
assert
os
.
path
.
exists
(
't2.btv'
)
...
...
@@ -140,7 +146,8 @@ class TestEntryCliExport:
'-c'
,
'test.entry.cli.test_export._my_compress:test.entry.cli.test_export._my_decompress'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
't1.btv'
)
assert
os
.
path
.
getsize
(
't1.btv'
)
<
330
assert
os
.
path
.
exists
(
't2.btv'
)
...
...
@@ -167,7 +174,8 @@ class TestEntryCliExport:
'-o'
,
'subpath/t3.btv'
,
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'subpath/t1.btv'
)
assert
os
.
path
.
getsize
(
'subpath/t1.btv'
)
<
290
assert
os
.
path
.
exists
(
'subpath/t2.btv'
)
...
...
@@ -190,7 +198,8 @@ class TestEntryCliExport:
'-d'
,
'subpath'
,
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'subpath/t1.btv'
)
assert
os
.
path
.
getsize
(
'subpath/t1.btv'
)
<
290
assert
os
.
path
.
exists
(
'subpath/t2.btv'
)
...
...
@@ -210,7 +219,8 @@ class TestEntryCliExport:
'-d'
,
'subpath'
,
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
not
os
.
path
.
exists
(
'subpath/t1.btv'
)
assert
os
.
path
.
exists
(
'subpath/t2.btv'
)
assert
os
.
path
.
getsize
(
'subpath/t2.btv'
)
<
290
...
...
@@ -229,7 +239,8 @@ class TestEntryCliExport:
'-o'
,
'ppp.btv'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
not
os
.
path
.
exists
(
't1.btv'
)
assert
not
os
.
path
.
exists
(
't2.btv'
)
assert
os
.
path
.
exists
(
'ppp.btv'
)
...
...
test/entry/cli/test_graph.py
浏览文件 @
ae999e17
...
...
@@ -7,7 +7,7 @@ import zlib
import
pytest
from
click.testing
import
CliRunner
from
hbutils.testing
import
cmdv
from
hbutils.testing
import
cmdv
,
OS
from
treevalue
import
FastTreeValue
,
dump
,
graphics
from
treevalue.entry.cli
import
treevalue_cli
...
...
@@ -36,7 +36,8 @@ class TestEntryCliGraph:
'-o'
,
'test_graph.svg'
,
'-o'
,
'test_graph.gv'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
7000
assert
os
.
path
.
exists
(
'test_graph.gv'
)
...
...
@@ -52,7 +53,8 @@ class TestEntryCliGraph:
'-o'
,
'test_graph.svg'
,
'-o'
,
'test_graph.gv'
,
'-O'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
not
os
.
path
.
exists
(
'test_graph.svg'
)
assert
not
os
.
path
.
exists
(
'test_graph.gv'
)
assert
len
(
result
.
output
)
<=
2500
...
...
@@ -66,7 +68,8 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'test.entry.cli.test_graph.t[12]'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
13000
...
...
@@ -76,7 +79,8 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'test.entry.cli.test_graph.*'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
17500
...
...
@@ -92,7 +96,8 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'g1.bg'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
6500
...
...
@@ -109,7 +114,8 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'*.bg'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
17500
...
...
@@ -122,7 +128,8 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'test.entry.cli.test_graph.t1'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
13000
...
...
@@ -135,7 +142,8 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'test.entry.cli.test_graph.t1'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
6500
...
...
@@ -149,7 +157,8 @@ class TestEntryCliGraph:
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
12000
...
...
@@ -162,7 +171,8 @@ class TestEntryCliGraph:
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
import
shutil
shutil
.
copy
(
'test_graph.svg'
,
os
.
path
.
join
(
_p
,
'test_graph.svg'
))
...
...
@@ -179,7 +189,8 @@ class TestEntryCliGraph:
'-t'
,
'first title'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
16500
...
...
@@ -196,7 +207,8 @@ class TestEntryCliGraph:
'-c'
,
'bgcolor=#ffffff00'
,
'-O'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
len
(
result
.
output
)
<=
6000
assert
'#ffffff00'
in
result
.
output
...
...
@@ -207,7 +219,9 @@ class TestEntryCliGraph:
'-c'
,
'bgcolor#ffffff00'
,
'-O'
],
)
assert
result
.
exit_code
!=
0
assert
result
.
exit_code
!=
0
,
f
'The running expected to raise RuntimeError '
\
f
'but not actually (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
"Configuration should be KEY=VALUE, but 'bgcolor#ffffff00' found."
in
result
.
output
@
unittest
.
skipUnless
(
cmdv
(
'dot'
),
'Dot installed only'
)
...
...
@@ -227,6 +241,10 @@ class TestEntryCliGraph:
args
=
[
'graph'
,
'-t'
,
'g1.bg'
,
'-o'
,
'test_graph.svg'
],
)
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
os
.
path
.
exists
(
'test_graph.svg'
)
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
1000
if
OS
.
windows
:
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
2000
else
:
assert
os
.
path
.
getsize
(
'test_graph.svg'
)
<=
1000
test/entry/cli/test_version.py
浏览文件 @
ae999e17
...
...
@@ -11,6 +11,7 @@ class TestEntryCliVersion:
runner
=
CliRunner
()
result
=
runner
.
invoke
(
treevalue_cli
,
args
=
[
'-v'
])
assert
result
.
exit_code
==
0
assert
result
.
exit_code
==
0
,
f
'Runtime Error (exitcode
{
result
.
exit_code
}
), '
\
f
'The output is:
\n
{
result
.
output
}
'
assert
__TITLE__
.
lower
()
in
result
.
stdout
.
lower
()
assert
__VERSION__
.
lower
()
in
result
.
stdout
.
lower
()
test/tree/general/test_general_benchmark.py
浏览文件 @
ae999e17
import
unittest
from
functools
import
lru_cache
from
typing
import
Optional
from
hbutils.testing
import
vpip
try
:
import
torch
except
ImportError
:
torch
=
None
import
pytest
import
torch
from
treevalue
import
TreeValue
,
func_treelize
,
FastTreeValue
_TREE_DATA_1
=
{
'a'
:
torch
.
randn
(
2
,
3
),
'x'
:
{
'c'
:
torch
.
randn
(
3
,
4
)}}
_TREE_1
=
FastTreeValue
(
_TREE_DATA_1
)
@
lru_cache
()
def
_get_tree
()
->
Optional
[
FastTreeValue
]:
if
torch
is
not
None
:
_TREE_DATA_1
=
{
'a'
:
torch
.
randn
(
2
,
3
),
'x'
:
{
'c'
:
torch
.
randn
(
3
,
4
)}}
return
FastTreeValue
(
_TREE_DATA_1
)
else
:
return
None
@
pytest
.
mark
.
benchmark
(
group
=
'treevalue_dynamic'
)
@
unittest
.
skipUnless
(
vpip
(
'torch'
)
>=
'1.1.0'
,
'Torch>=1.1.0 only'
)
class
TestTreeGeneralBenchmark
:
def
test_dynamic_execute
(
self
,
benchmark
):
def
sin
(
t
):
return
t
.
sin
()
return
benchmark
(
sin
,
_
TREE_1
)
return
benchmark
(
sin
,
_
get_tree
()
)
def
test_static_execute
(
self
,
benchmark
):
sinf
=
func_treelize
(
return_type
=
TreeValue
)(
torch
.
sin
)
...
...
@@ -21,4 +38,4 @@ class TestTreeGeneralBenchmark:
def
sin
(
t
):
return
sinf
(
t
)
return
benchmark
(
sin
,
_
TREE_1
)
return
benchmark
(
sin
,
_
get_tree
()
)
test/tree/general/test_tensor.py
浏览文件 @
ae999e17
import
unittest
import
pytest
import
torch
from
hbutils.testing
import
vpip
try
:
import
torch
except
ImportError
:
torch
=
None
from
treevalue.tree
import
func_treelize
,
FastTreeValue
@
pytest
.
mark
.
unittest
@
unittest
.
skipUnless
(
vpip
(
'torch'
)
>=
'1.1.0'
,
'Torch>=1.1.0 only'
)
def
test_for_torch_support
():
sin
=
func_treelize
()(
torch
.
sin
)
cos
=
func_treelize
()(
torch
.
cos
)
# the same sin function
...
...
test/utils/test_formattree.py
浏览文件 @
ae999e17
...
...
@@ -19,6 +19,8 @@
# And in this library 'treevalue', Apache Licence Version 2.0 is used as well.
import
doctest
import
io
import
os
from
operator
import
itemgetter
from
textwrap
import
dedent
...
...
@@ -31,6 +33,11 @@ from treevalue.utils import (
)
def
_process_linesep
(
s
:
str
)
->
str
:
with
io
.
StringIO
(
s
)
as
sf
:
return
os
.
linesep
.
join
([
line
.
rstrip
(
'
\r\n
'
)
for
line
in
sf
])
@
pytest
.
mark
.
unittest
class
TestFormatTree
(
TestCase
):
...
...
@@ -40,9 +47,9 @@ class TestFormatTree(TestCase):
def
test_single_node_tree
(
self
):
tree
=
(
'foo'
,
[])
output
=
self
.
format_tree
(
tree
)
self
.
assertEqual
(
dedent
(
u
'''
\
self
.
assertEqual
(
_process_linesep
(
dedent
(
u
'''
\
foo
'''
)
,
output
)
'''
)
),
_process_linesep
(
output
)
)
def
test_single_level_tree
(
self
):
tree
=
(
...
...
@@ -53,12 +60,12 @@ class TestFormatTree(TestCase):
],
)
output
=
self
.
format_tree
(
tree
)
self
.
assertEqual
(
dedent
(
u
'''
\
self
.
assertEqual
(
_process_linesep
(
dedent
(
u
'''
\
foo
├── bar
├── baz
└── qux
'''
)
,
output
)
'''
)
),
_process_linesep
(
output
)
)
def
test_single_level_tree_with_ascii
(
self
):
tree
=
(
...
...
@@ -69,12 +76,12 @@ class TestFormatTree(TestCase):
],
)
output
=
self
.
format_tree
(
tree
,
encoding
=
'ascii'
)
self
.
assertEqual
(
dedent
(
u
'''
\
self
.
assertEqual
(
_process_linesep
(
dedent
(
u
'''
\
foo
+-- bar
+-- baz
`-- qux
'''
)
,
output
)
'''
)
),
_process_linesep
(
output
)
)
def
test_multi_level_tree
(
self
):
tree
=
(
...
...
@@ -88,14 +95,14 @@ class TestFormatTree(TestCase):
],
)
output
=
self
.
format_tree
(
tree
)
self
.
assertEqual
(
dedent
(
u
'''
\
self
.
assertEqual
(
_process_linesep
(
dedent
(
u
'''
\
foo
├── bar
│ ├── a
│ └── b
├── baz
└── qux
'''
)
,
output
)
'''
)
),
_process_linesep
(
output
)
)
def
test_multi_level_on_last_node_tree
(
self
):
tree
=
(
...
...
@@ -109,14 +116,14 @@ class TestFormatTree(TestCase):
],
)
output
=
self
.
format_tree
(
tree
)
self
.
assertEqual
(
dedent
(
u
'''
\
self
.
assertEqual
(
_process_linesep
(
dedent
(
u
'''
\
foo
├── bar
├── baz
└── qux
├── a
└── b
'''
)
,
output
)
'''
)
),
_process_linesep
(
output
)
)
def
test_acceptance
(
self
):
output
=
self
.
format_tree
(
ACCEPTANCE_INPUT
)
...
...
@@ -140,7 +147,7 @@ class TestFormatTree(TestCase):
],
)
output
=
self
.
format_tree
(
tree
)
self
.
assertEqual
(
dedent
(
u
'''
\
self
.
assertEqual
(
_process_linesep
(
dedent
(
u
'''
\
foo
├── bar
│ frob
...
...
@@ -151,7 +158,7 @@ class TestFormatTree(TestCase):
├── baz
└── qux
frab
'''
)
,
output
)
'''
)
),
_process_linesep
(
output
)
)
def
d
(
name
,
files
):
...
...
treevalue/entry/cli/graph.py
浏览文件 @
ae999e17
import
codecs
import
os
import
shutil
import
tempfile
import
warnings
from
collections
import
OrderedDict
from
functools
import
partial
...
...
@@ -61,10 +59,7 @@ def _save_source_code(g: Digraph, path: str):
def
_save_image
(
g
:
Digraph
,
path
:
str
,
fmt
:
str
):
with
tempfile
.
TemporaryDirectory
()
as
tmpdir
:
with
tempfile
.
NamedTemporaryFile
(
dir
=
tmpdir
)
as
tmpfile
:
svg_file
=
g
.
render
(
tmpfile
.
name
,
format
=
fmt
)
shutil
.
copy
(
svg_file
,
path
)
g
.
render
(
path
,
format
=
fmt
)
_IMAGE_FMTS
=
{
'svg'
,
'png'
}
...
...
HansBug
😆
@HansBug
mentioned in commit
b71e3c82
·
7月 14, 2022
mentioned in commit
b71e3c82
mentioned in commit b71e3c824c8ec21d66c3743e630fe9cb4839bedb
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录