2017-10-05 11:57:46 +00:00
|
|
|
import io
|
|
|
|
import unittest
|
2017-10-24 08:39:34 +00:00
|
|
|
from mock import patch
|
2017-10-05 11:57:46 +00:00
|
|
|
|
|
|
|
from pylorax import buildstamp
|
|
|
|
|
|
|
|
class BuildStampTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.bstamp = buildstamp.BuildStamp(
|
|
|
|
'Lorax Tests',
|
|
|
|
'0.1',
|
|
|
|
'https://github.com/rhinstaller/lorax/issues',
|
|
|
|
True,
|
|
|
|
'noarch'
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_write_produces_file_with_expected_content(self):
|
|
|
|
out_file = io.StringIO()
|
2017-10-24 08:39:34 +00:00
|
|
|
# io.StringIO.write accepts unicode,
|
|
|
|
# but on Python 2 BuildStamp.write() passes strings to this method
|
|
|
|
out_file.orig_write = out_file.write
|
|
|
|
out_file.write = lambda s: out_file.orig_write(unicode(s))
|
|
|
|
|
2017-10-05 11:57:46 +00:00
|
|
|
with patch.object(out_file, 'close'):
|
2017-10-24 08:39:34 +00:00
|
|
|
with patch('pylorax.buildstamp.open', create=True, return_value=out_file):
|
2017-10-05 11:57:46 +00:00
|
|
|
self.bstamp.write('/tmp/stamp.ini')
|
|
|
|
self.assertIn("[Main]\nProduct=Lorax Tests\nVersion=0.1\nBugURL=https://github.com/rhinstaller/lorax/issues\nIsFinal=True", out_file.getvalue())
|
|
|
|
self.assertIn("[Compose]\nLorax=devel", out_file.getvalue())
|