test_installerbuilder.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import io
  2. from os.path import join as pjoin
  3. import shutil
  4. import tempfile
  5. import unittest
  6. from .utils import assert_is_file, test_dir
  7. from nsist import InstallerBuilder, DEFAULT_ICON
  8. sample_preamble = pjoin(test_dir, u'sample_preamble.py')
  9. class TestInstallerBuilder(unittest.TestCase):
  10. def setUp(self):
  11. self.target = tempfile.mkdtemp()
  12. def tearDown(self):
  13. shutil.rmtree(self.target)
  14. def test_prepare_shortcuts(self):
  15. shortcuts = {'sc1': {'entry_point': 'norwegian.blue:parrot',
  16. 'icon': DEFAULT_ICON,
  17. 'console': False,
  18. 'extra_preamble': sample_preamble,
  19. }
  20. }
  21. ib = InstallerBuilder("Test App", "1.0", shortcuts, build_dir=self.target)
  22. ib.prepare_shortcuts()
  23. scfile = pjoin(self.target, 'sc1.launch.pyw')
  24. assert_is_file(scfile)
  25. with io.open(scfile, 'r', encoding='utf-8') as f:
  26. contents = f.read()
  27. last2lines = [l.strip() for l in contents.rstrip().splitlines()[-2:]]
  28. assert last2lines == ['from norwegian.blue import parrot', 'parrot()']
  29. with io.open(sample_preamble, 'r', encoding='utf-8') as f:
  30. preamble_contents = f.read().strip()
  31. assert preamble_contents in contents