-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
52 lines (38 loc) · 1.29 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import unittest
from src import IsWSL
# To test if IsWSL works correctly, we must know whether we trully are in WSL or not.
# Doing that automatically would be circular logic, so instead we pass it as an argument
# from outside.
platform = ""
def usage() -> str:
return """Usage:
python3 is_wsl_test.py --help Print this message and exit.
python3 is_wsl_test.py PLATFORM Run the test suite.
PLATFORM
The machine or container you're running the tests in. Either WSL or something else.
"""
class TestIsWSL(unittest.TestCase):
def test_IsWsl(self):
got = IsWSL()
if platform.lower() == "wsl":
self.assertTrue(
got, f"expected IsWSL to return true in platform {platform}"
)
return
self.assertFalse(got, f"expected IsWSL to return false in platform {platform}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print(usage())
sys.exit(5)
if sys.argv[1] == "--help":
print(usage())
sys.exit(0)
platform = sys.argv[1]
runner = unittest.TextTestRunner()
suite = unittest.TestSuite()
suite.addTests([unittest.TestLoader().loadTestsFromTestCase(TestIsWSL)])
r = runner.run(suite)
if r.wasSuccessful():
sys.exit(0)
sys.exit(1)