aboutsummaryrefslogtreecommitdiffstats
path: root/tests.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2016-07-27 17:45:58 +0300
committerFilipp Lepalaan <filipp@mac.com>2016-07-27 17:45:58 +0300
commit8da0c51d7effd8d13f2ea562e2f0a55f824ee7b1 (patch)
treee7423ecc5b340140a18662083c9394cf8c691f98 /tests.py
downloadsystem_profiler-8da0c51d7effd8d13f2ea562e2f0a55f824ee7b1.tar.gz
system_profiler-8da0c51d7effd8d13f2ea562e2f0a55f824ee7b1.tar.bz2
system_profiler-8da0c51d7effd8d13f2ea562e2f0a55f824ee7b1.zip
Initial commit
Diffstat (limited to 'tests.py')
-rw-r--r--tests.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests.py b/tests.py
new file mode 100644
index 0000000..553b5ed
--- /dev/null
+++ b/tests.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+
+import logging
+import subprocess
+from unittest import main, skip, TestCase
+
+import system_profiler
+
+
+class SystemProfilerTestCase(TestCase):
+ def testSerialNumber(self):
+ sn = system_profiler.get('Hardware', 'serial_number')
+ self.assertTrue(len(sn) > 8)
+
+ def testInvalidType(self):
+ with self.assertRaises(Exception):
+ system_profiler.SystemProfile('Whatever')
+
+ def testKeys(self):
+ self.assertTrue(len(system_profiler.keys()) > 3)
+
+ def testTypes(self):
+ self.assertIn('Hardware', system_profiler.types())
+
+ def testOsVersion(self):
+ """
+ Check that the OS version we get from SP is contained
+ in the output of sw_vers
+ """
+ build = subprocess.check_output(['sw_vers', '-buildVersion']).strip()
+ software = system_profiler.SystemProfile('Software')
+ self.assertIn(build, software.os_version)
+
+ def testOsVersionShortcut(self):
+ build = subprocess.check_output(['sw_vers', '-buildVersion']).strip()
+ self.assertTrue(build in system_profiler.get('Software', 'os_version'))
+
+
+class AppsTestCase(TestCase):
+ def setUp(self):
+ self.profile = system_profiler.SystemProfile('Applications')
+
+ def testFindStickes(self):
+ results = self.profile.find('_name', 'Stickies')
+ self.assertTrue(len(results) > 0)
+
+ def testStickiesVersion(self):
+ results = self.profile.find('_name', 'Stickies')
+ self.assertEquals(results[0]['version'], '10.0')
+
+ def testFindApplications(self):
+ results = self.profile.find('path', '/Applications')
+ self.assertTrue(len(results) > 10)
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.DEBUG)
+ main()