test_filewriter.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #! /usr/bin/env python3
  2. #
  3. # Copyright (C) 2017, Niels Thykier <niels@thykier.net>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. import tempfile
  19. import shutil
  20. from base_test import DakTestCase
  21. from daklib.filewriter import (BinaryContentsFileWriter,
  22. SourceContentsFileWriter,
  23. SourcesFileWriter,
  24. PackagesFileWriter,
  25. TranslationFileWriter)
  26. SUITE = 'unstable'
  27. COMPONENT = 'main'
  28. ARCH = 'amd64'
  29. LANG = 'en'
  30. class FileWriterTest(DakTestCase):
  31. def test_writer_test(self):
  32. tmpdir = tempfile.mkdtemp()
  33. try:
  34. dbcfw = BinaryContentsFileWriter(archive=tmpdir,
  35. suite=SUITE,
  36. component=COMPONENT,
  37. architecture=ARCH,
  38. debtype='deb')
  39. ubcdw = BinaryContentsFileWriter(archive=tmpdir,
  40. suite=SUITE,
  41. component=COMPONENT,
  42. architecture=ARCH,
  43. debtype='udeb')
  44. scfw = SourceContentsFileWriter(archive=tmpdir,
  45. suite=SUITE,
  46. component=COMPONENT)
  47. sfw = SourcesFileWriter(archive=tmpdir,
  48. suite=SUITE,
  49. component=COMPONENT)
  50. dpfw = PackagesFileWriter(archive=tmpdir,
  51. suite=SUITE,
  52. component=COMPONENT,
  53. architecture=ARCH,
  54. debtype='deb')
  55. upfw = PackagesFileWriter(archive=tmpdir,
  56. suite=SUITE,
  57. component=COMPONENT,
  58. architecture=ARCH,
  59. debtype='udeb')
  60. tfw = TranslationFileWriter(archive=tmpdir,
  61. suite=SUITE,
  62. component=COMPONENT,
  63. language=LANG)
  64. file_writers = [
  65. dbcfw,
  66. ubcdw,
  67. scfw,
  68. sfw,
  69. dpfw,
  70. upfw,
  71. tfw,
  72. ]
  73. for writer in file_writers:
  74. fd = writer.open()
  75. fd.write('hallo world')
  76. writer.close()
  77. # TODO, verify that it created the correct files.
  78. # (currently we just test it does not crash).
  79. finally:
  80. shutil.rmtree(tmpdir)