[PATCH 1/2] Convert host checking to pytest.

Amar Takhar amar at rtems.org
Fri Mar 13 23:28:27 UTC 2020


---
 rtemstoolkit/darwin.py          |  5 -----
 rtemstoolkit/freebsd.py         |  5 -----
 rtemstoolkit/host.py            | 14 --------------
 rtemstoolkit/linux.py           |  5 -----
 rtemstoolkit/netbsd.py          |  5 -----
 rtemstoolkit/solaris.py         |  5 -----
 rtemstoolkit/tests/test_host.py | 32 ++++++++++++++++++++++++++++++++
 rtemstoolkit/windows.py         |  5 -----
 8 files changed, 32 insertions(+), 44 deletions(-)
 create mode 100644 rtemstoolkit/tests/test_host.py

diff --git a/rtemstoolkit/darwin.py b/rtemstoolkit/darwin.py
index e780d1d..b9e17cf 100644
--- a/rtemstoolkit/darwin.py
+++ b/rtemstoolkit/darwin.py
@@ -76,8 +76,3 @@ def overrides():
     defines['_build_arch']   = defines['_host_arch']
 
     return defines
-
-if __name__ == '__main__':
-    import pprint
-    pprint.pprint(cpus())
-    pprint.pprint(overrides())
diff --git a/rtemstoolkit/freebsd.py b/rtemstoolkit/freebsd.py
index ed16140..6e40c34 100644
--- a/rtemstoolkit/freebsd.py
+++ b/rtemstoolkit/freebsd.py
@@ -97,8 +97,3 @@ def overrides():
             break
 
     return defines
-
-if __name__ == '__main__':
-    import pprint
-    pprint.pprint(cpus())
-    pprint.pprint(overrides())
diff --git a/rtemstoolkit/host.py b/rtemstoolkit/host.py
index 01aae07..67b006a 100644
--- a/rtemstoolkit/host.py
+++ b/rtemstoolkit/host.py
@@ -103,17 +103,3 @@ def label(mode = 'all'):
     if mode == 'all':
         return '%s (%s)' % (compact, extended)
     raise error.general('invalid platform mode: %s' % (mode))
-
-if __name__ == '__main__':
-    import pprint
-    print('Python\'s OS name: %s' % (os.name))
-    load()
-    print('Name      : %s' % (name))
-    if is_windows:
-        status = 'Yes'
-    else:
-        status = 'No'
-    print('Windows   : %s' % (status))
-    print('CPUs      : %d' % (cpus()))
-    print('Overrides :')
-    pprint.pprint(overrides())
diff --git a/rtemstoolkit/linux.py b/rtemstoolkit/linux.py
index 21f6f97..15b8528 100644
--- a/rtemstoolkit/linux.py
+++ b/rtemstoolkit/linux.py
@@ -134,8 +134,3 @@ def overrides():
     defines['_build_arch']   = defines['_host_arch']
 
     return defines
-
-if __name__ == '__main__':
-    import pprint
-    pprint.pprint(cpus())
-    pprint.pprint(overrides())
diff --git a/rtemstoolkit/netbsd.py b/rtemstoolkit/netbsd.py
index 1d9a11f..eab9353 100644
--- a/rtemstoolkit/netbsd.py
+++ b/rtemstoolkit/netbsd.py
@@ -90,8 +90,3 @@ def overrides():
             break
 
     return defines
-
-if __name__ == '__main__':
-    import pprint
-    pprint.pprint(cpus())
-    pprint.pprint(overrides())
diff --git a/rtemstoolkit/solaris.py b/rtemstoolkit/solaris.py
index 79ddd75..1b265da 100644
--- a/rtemstoolkit/solaris.py
+++ b/rtemstoolkit/solaris.py
@@ -83,8 +83,3 @@ def overrides():
     defines['_build_arch']   = defines['_host_arch']
 
     return defines
-
-if __name__ == '__main__':
-    import pprint
-    pprint.pprint(cpus())
-    pprint.pprint(overrides())
diff --git a/rtemstoolkit/tests/test_host.py b/rtemstoolkit/tests/test_host.py
new file mode 100644
index 0000000..4b1bf00
--- /dev/null
+++ b/rtemstoolkit/tests/test_host.py
@@ -0,0 +1,32 @@
+import pytest
+
+from rtemstoolkit import host
+import re
+
+
+def test_cpu():
+	assert type(host.cpus()) is int
+
+def test_overrides():
+	assert type(host.overrides()) is dict
+
+def test_label_system():
+	assert host.label(mode="system") is not None
+
+def test_label_compact():
+	assert re.match("^[a-zA-Z]*-.*-.*$", host.label(mode="compact"))
+
+
+def test_label_extended():
+	assert re.match("^[a-zA-Z]* .*$", host.label(mode="extended"))
+
+def test_label_extended():
+	assert re.match("^[a-zA-Z]* .*$", host.label(mode="extended"))
+
+def test_label_all():
+	assert re.match("^[a-zA-Z]*-.*-.* \\(.*\\)$", host.label(mode="all"))
+
+def test_label_error():
+	from rtemstoolkit.error import general
+	with pytest.raises(general, match=r"^error: invalid platform mode: _nonexistent_$"):
+		assert host.label(mode="_nonexistent_")
diff --git a/rtemstoolkit/windows.py b/rtemstoolkit/windows.py
index 802263b..585cddf 100644
--- a/rtemstoolkit/windows.py
+++ b/rtemstoolkit/windows.py
@@ -132,8 +132,3 @@ def overrides():
         '___setup_shell': ('exe',     'required', '%{__sh}')
         }
     return defines
-
-if __name__ == '__main__':
-    import pprint
-    pprint.pprint(cpus())
-    pprint.pprint(overrides())
-- 
2.25.0



More information about the devel mailing list