test_win32.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.python.win32}.
  5. """
  6. from twisted.trial import unittest
  7. from twisted.python.runtime import platform
  8. from twisted.python import win32
  9. class CommandLineQuotingTests(unittest.TestCase):
  10. """
  11. Tests for L{cmdLineQuote}.
  12. """
  13. def test_argWithoutSpaces(self):
  14. """
  15. Calling C{cmdLineQuote} with an argument with no spaces should
  16. return the argument unchanged.
  17. """
  18. self.assertEqual(win32.cmdLineQuote('an_argument'), 'an_argument')
  19. def test_argWithSpaces(self):
  20. """
  21. Calling C{cmdLineQuote} with an argument containing spaces should
  22. return the argument surrounded by quotes.
  23. """
  24. self.assertEqual(win32.cmdLineQuote('An Argument'), '"An Argument"')
  25. def test_emptyStringArg(self):
  26. """
  27. Calling C{cmdLineQuote} with an empty string should return a
  28. quoted empty string.
  29. """
  30. self.assertEqual(win32.cmdLineQuote(''), '""')
  31. class ProgramPathsTests(unittest.TestCase):
  32. """
  33. Tests for L{getProgramsMenuPath} and L{getProgramFilesPath}.
  34. """
  35. def test_getProgramsMenuPath(self):
  36. """
  37. L{getProgramsMenuPath} guesses the programs menu path on non-win32
  38. platforms. On non-win32 it will try to figure out the path by
  39. examining the registry.
  40. """
  41. if not platform.isWindows():
  42. self.assertEqual(win32.getProgramsMenuPath(),
  43. "C:\\Windows\\Start Menu\\Programs")
  44. else:
  45. self.assertIsInstance(win32.getProgramsMenuPath(), str)
  46. def test_getProgramFilesPath(self):
  47. """
  48. L{getProgramFilesPath} returns the "program files" path on win32.
  49. """
  50. self.assertIsInstance(win32.getProgramFilesPath(), str)
  51. if not platform.isWindows():
  52. test_getProgramFilesPath.skip = (
  53. "Cannot figure out the program files path on non-win32 platform")
  54. def test_deprecationGetProgramFilesPath(self):
  55. """
  56. L{getProgramFilesPath} has been deprecated.
  57. """
  58. win32.getProgramFilesPath()
  59. emittedWarnings = self.flushWarnings(
  60. [self.test_deprecationGetProgramFilesPath])
  61. self.assertEqual(len(emittedWarnings), 1)
  62. self.assertIs(emittedWarnings[0]["category"], DeprecationWarning)
  63. self.assertEqual(
  64. emittedWarnings[0]["message"],
  65. "twisted.python.win32.getProgramFilesPath was deprecated in "
  66. "Twisted 15.3.0")
  67. if not platform.isWindows():
  68. test_deprecationGetProgramFilesPath.skip = (
  69. "Deprecation test for getProgramFilesPath() is Windows only")
  70. def test_deprecationGetProgramsMenuPath(self):
  71. """
  72. L{getProgramsMenuPath} has been deprecated.
  73. """
  74. win32.getProgramsMenuPath()
  75. emittedWarnings = self.flushWarnings(
  76. [self.test_deprecationGetProgramsMenuPath])
  77. self.assertEqual(len(emittedWarnings), 1)
  78. self.assertIs(emittedWarnings[0]["category"], DeprecationWarning)
  79. self.assertEqual(
  80. emittedWarnings[0]["message"],
  81. "twisted.python.win32.getProgramsMenuPath was deprecated in "
  82. "Twisted 15.3.0")