File: test_cli.py

package info (click to toggle)
python-cpuinfo 5.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 564 kB
  • sloc: python: 7,625; makefile: 9
file content (47 lines) | stat: -rw-r--r-- 1,114 bytes parent folder | download | duplicates (2)
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


import unittest
from cpuinfo import *
import helpers



class TestCLI(unittest.TestCase):
	def setUp(self):
		helpers.backup_data_source(cpuinfo)

	def tearDown(self):
		helpers.restore_data_source(cpuinfo)

	def test_json(self):
		from subprocess import Popen, PIPE
		import json

		command = [sys.executable, 'cpuinfo/cpuinfo.py', '--json']
		p1 = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE)
		output = p1.communicate()[0]

		self.assertEqual(0, p1.returncode)

		if not IS_PY2:
			output = output.decode(encoding='UTF-8')

		info = json.loads(output, object_hook = cpuinfo._utf_to_str)

		self.assertEqual(list(cpuinfo.CPUINFO_VERSION), info['cpuinfo_version'])

	def test_default(self):
		from subprocess import Popen, PIPE

		command = [sys.executable, 'cpuinfo/cpuinfo.py']
		p1 = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE)
		output = p1.communicate()[0]

		self.assertEqual(0, p1.returncode)

		if not IS_PY2:
			output = output.decode(encoding='UTF-8')

		version = output.split('Cpuinfo Version: ')[1].split('\n')[0].strip()

		self.assertEqual(str(cpuinfo.CPUINFO_VERSION), version)