expect_unittest.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (c) 2019 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Tests for the expect module."""
  15. import expect
  16. from spirv_test_framework import TestStatus
  17. import re
  18. import unittest
  19. class TestStdoutMatchADotC(expect.StdoutMatch):
  20. expected_stdout = re.compile('a.c')
  21. class TestExpect(unittest.TestCase):
  22. def test_get_object_name(self):
  23. """Tests get_object_filename()."""
  24. source_and_object_names = [('a.vert', 'a.vert.spv'),
  25. ('b.frag', 'b.frag.spv'),
  26. ('c.tesc', 'c.tesc.spv'),
  27. ('d.tese', 'd.tese.spv'),
  28. ('e.geom', 'e.geom.spv'),
  29. ('f.comp', 'f.comp.spv'),
  30. ('file', 'file.spv'), ('file.', 'file.spv'),
  31. ('file.uk',
  32. 'file.spv'), ('file.vert.',
  33. 'file.vert.spv'),
  34. ('file.vert.bla',
  35. 'file.vert.spv')]
  36. actual_object_names = [
  37. expect.get_object_filename(f[0]) for f in source_and_object_names
  38. ]
  39. expected_object_names = [f[1] for f in source_and_object_names]
  40. self.assertEqual(actual_object_names, expected_object_names)
  41. def test_stdout_match_regex_has_match(self):
  42. test = TestStdoutMatchADotC()
  43. status = TestStatus(
  44. test_manager=None,
  45. returncode=0,
  46. stdout=b'0abc1',
  47. stderr=None,
  48. directory=None,
  49. inputs=None,
  50. input_filenames=None)
  51. self.assertTrue(test.check_stdout_match(status)[0])
  52. def test_stdout_match_regex_no_match(self):
  53. test = TestStdoutMatchADotC()
  54. status = TestStatus(
  55. test_manager=None,
  56. returncode=0,
  57. stdout=b'ab',
  58. stderr=None,
  59. directory=None,
  60. inputs=None,
  61. input_filenames=None)
  62. self.assertFalse(test.check_stdout_match(status)[0])
  63. def test_stdout_match_regex_empty_stdout(self):
  64. test = TestStdoutMatchADotC()
  65. status = TestStatus(
  66. test_manager=None,
  67. returncode=0,
  68. stdout=b'',
  69. stderr=None,
  70. directory=None,
  71. inputs=None,
  72. input_filenames=None)
  73. self.assertFalse(test.check_stdout_match(status)[0])