qubes-installer-qubes-os/anaconda/old_tests/pyanaconda_test/product_test.py
Marek Marczykowski-Górecki f73b3741f0 Update anaconda to 20.25.16
Apply result of "git diff anaconda-18.37.11-1..anaconda-20.25.16-1" and
resolve conflicts.
2014-04-08 05:50:31 +02:00

83 lines
2.5 KiB
Python

#!/usr/bin/python
import mock
import sys
import __builtin__
import ConfigParser
class ProductTest(mock.TestCase):
def setUp(self):
self.setupModules(['_isys', 'block', 'os'])
self.fs = mock.DiskIO()
# os module global mock
self.modifiedModule("os")
os = sys.modules['os']
os.access = mock.Mock(return_value=False)
os.uname.return_value = ('', '', '', '', 'i386')
os.environ = {}
# fake /tmp/product/.buildstamp file
self.BUGURL = 'http://bug.url'
self.FINAL = 'false'
self.ARCH = 'i386'
self.NAME = '__anaconda'
self.UUID = '123456.%s' % self.ARCH
self.VERSION = '14'
self.FILENAME = '/tmp/product/.buildstamp'
self.FILE = \
"[Main]\n"\
"BugURL: %s\n"\
"IsFinal: %s\n"\
"Arch: %s\n"\
"Product: %s\n"\
"UUID: %s\n"\
"Version: %s\n" % \
(self.BUGURL, self.FINAL, self.ARCH, self.NAME, self.UUID, self.VERSION)
self.fs.open(self.FILENAME, 'w').write(self.FILE)
# mock builtin open function
self.open = __builtin__.open
__builtin__.open = self.fs.open
if 'pyanaconda.product' in sys.modules:
del(sys.modules["pyanaconda.product"])
def tearDown(self):
__builtin__.open = self.open
self.tearDownModules()
def bug_url_test(self):
sys.modules['os'].access = mock.Mock(return_value=True)
import pyanaconda.product
self.assertEqual(pyanaconda.product.bugUrl, self.BUGURL)
def is_final_test(self):
sys.modules['os'].access = mock.Mock(return_value=True)
import pyanaconda.product
self.assertFalse(pyanaconda.product.isFinal)
def product_arch_test(self):
sys.modules['os'].access = mock.Mock(return_value=True)
import pyanaconda.product
self.assertEqual(pyanaconda.product.productArch, self.ARCH)
def product_name_test(self):
sys.modules['os'].access = mock.Mock(return_value=True)
import pyanaconda.product
self.assertEqual(pyanaconda.product.productName, self.NAME)
def product_stamp_test(self):
sys.modules['os'].access = mock.Mock(return_value=True)
import pyanaconda.product
self.assertEqual(pyanaconda.product.productStamp, self.UUID)
def product_version_test(self):
sys.modules['os'].access = mock.Mock(return_value=True)
import pyanaconda.product
self.assertEqual(pyanaconda.product.productVersion, self.VERSION)