mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This reverts commit 3a68155ce0973c005457593375801a2cc19de54f. Reverted https://github.com/pytorch/pytorch/pull/76984 on behalf of https://github.com/janeyx99
96 lines
2.4 KiB
Python
96 lines
2.4 KiB
Python
import unittest
|
|
|
|
from tools import extract_scripts
|
|
|
|
requirements_sh = """
|
|
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
pip install -r requirements.txt
|
|
""".strip()
|
|
|
|
hello_sh = """
|
|
#!/usr/bin/env sh
|
|
set -e
|
|
echo hello world
|
|
""".strip()
|
|
|
|
|
|
class TestExtractScripts(unittest.TestCase):
|
|
def test_extract_none(self) -> None:
|
|
self.assertEqual(
|
|
extract_scripts.extract(
|
|
{
|
|
"name": "Checkout PyTorch",
|
|
"uses": "zhouzhuojie/checkout@05b13c9a0d21f08f6d5e64a1d5042246d13619d9",
|
|
}
|
|
),
|
|
None,
|
|
)
|
|
|
|
def test_extract_run_default_bash(self) -> None:
|
|
self.assertEqual(
|
|
extract_scripts.extract(
|
|
{
|
|
"name": "Install requirements",
|
|
"run": "pip install -r requirements.txt",
|
|
}
|
|
),
|
|
{
|
|
"extension": ".sh",
|
|
"script": requirements_sh,
|
|
},
|
|
)
|
|
|
|
def test_extract_run_sh(self) -> None:
|
|
self.assertEqual(
|
|
extract_scripts.extract(
|
|
{
|
|
"name": "Hello world",
|
|
"run": "echo hello world",
|
|
"shell": "sh",
|
|
}
|
|
),
|
|
{
|
|
"extension": ".sh",
|
|
"script": hello_sh,
|
|
},
|
|
)
|
|
|
|
def test_extract_run_py(self) -> None:
|
|
self.assertEqual(
|
|
extract_scripts.extract(
|
|
{
|
|
"name": "Hello world",
|
|
"run": 'print("Hello!")',
|
|
"shell": "python",
|
|
}
|
|
),
|
|
{
|
|
"extension": ".py",
|
|
"script": 'print("Hello!")',
|
|
},
|
|
)
|
|
|
|
def test_extract_github_script(self) -> None:
|
|
self.assertEqual(
|
|
# https://github.com/actions/github-script/tree/v3.1.1#reading-step-results
|
|
extract_scripts.extract(
|
|
{
|
|
"uses": "actions/github-script@v3",
|
|
"id": "set-result",
|
|
"with": {
|
|
"script": 'return "Hello!"',
|
|
"result-encoding": "string",
|
|
},
|
|
}
|
|
),
|
|
{
|
|
"extension": ".js",
|
|
"script": 'return "Hello!"',
|
|
},
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|