diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_hooks.py | 60 | ||||
| -rw-r--r-- | tests/test_project.py | 39 |
2 files changed, 60 insertions, 39 deletions
diff --git a/tests/test_hooks.py b/tests/test_hooks.py new file mode 100644 index 00000000..ed8268df --- /dev/null +++ b/tests/test_hooks.py | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | # -*- coding:utf-8 -*- | ||
| 2 | # | ||
| 3 | # Copyright (C) 2019 The Android Open Source Project | ||
| 4 | # | ||
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | # you may not use this file except in compliance with the License. | ||
| 7 | # You may obtain a copy of the License at | ||
| 8 | # | ||
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | # | ||
| 11 | # Unless required by applicable law or agreed to in writing, software | ||
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | # See the License for the specific language governing permissions and | ||
| 15 | # limitations under the License. | ||
| 16 | |||
| 17 | """Unittests for the hooks.py module.""" | ||
| 18 | |||
| 19 | from __future__ import print_function | ||
| 20 | |||
| 21 | import hooks | ||
| 22 | import unittest | ||
| 23 | |||
| 24 | class RepoHookShebang(unittest.TestCase): | ||
| 25 | """Check shebang parsing in RepoHook.""" | ||
| 26 | |||
| 27 | def test_no_shebang(self): | ||
| 28 | """Lines w/out shebangs should be rejected.""" | ||
| 29 | DATA = ( | ||
| 30 | '', | ||
| 31 | '# -*- coding:utf-8 -*-\n', | ||
| 32 | '#\n# foo\n', | ||
| 33 | '# Bad shebang in script\n#!/foo\n' | ||
| 34 | ) | ||
| 35 | for data in DATA: | ||
| 36 | self.assertIsNone(hooks.RepoHook._ExtractInterpFromShebang(data)) | ||
| 37 | |||
| 38 | def test_direct_interp(self): | ||
| 39 | """Lines whose shebang points directly to the interpreter.""" | ||
| 40 | DATA = ( | ||
| 41 | ('#!/foo', '/foo'), | ||
| 42 | ('#! /foo', '/foo'), | ||
| 43 | ('#!/bin/foo ', '/bin/foo'), | ||
| 44 | ('#! /usr/foo ', '/usr/foo'), | ||
| 45 | ('#! /usr/foo -args', '/usr/foo'), | ||
| 46 | ) | ||
| 47 | for shebang, interp in DATA: | ||
| 48 | self.assertEqual(hooks.RepoHook._ExtractInterpFromShebang(shebang), | ||
| 49 | interp) | ||
| 50 | |||
| 51 | def test_env_interp(self): | ||
| 52 | """Lines whose shebang launches through `env`.""" | ||
| 53 | DATA = ( | ||
| 54 | ('#!/usr/bin/env foo', 'foo'), | ||
| 55 | ('#!/bin/env foo', 'foo'), | ||
| 56 | ('#! /bin/env /bin/foo ', '/bin/foo'), | ||
| 57 | ) | ||
| 58 | for shebang, interp in DATA: | ||
| 59 | self.assertEqual(hooks.RepoHook._ExtractInterpFromShebang(shebang), | ||
| 60 | interp) | ||
diff --git a/tests/test_project.py b/tests/test_project.py index 67574cb8..4e710ae5 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -44,45 +44,6 @@ def TempGitTree(): | |||
| 44 | platform_utils.rmtree(tempdir) | 44 | platform_utils.rmtree(tempdir) |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | class RepoHookShebang(unittest.TestCase): | ||
| 48 | """Check shebang parsing in RepoHook.""" | ||
| 49 | |||
| 50 | def test_no_shebang(self): | ||
| 51 | """Lines w/out shebangs should be rejected.""" | ||
| 52 | DATA = ( | ||
| 53 | '', | ||
| 54 | '# -*- coding:utf-8 -*-\n', | ||
| 55 | '#\n# foo\n', | ||
| 56 | '# Bad shebang in script\n#!/foo\n' | ||
| 57 | ) | ||
| 58 | for data in DATA: | ||
| 59 | self.assertIsNone(project.RepoHook._ExtractInterpFromShebang(data)) | ||
| 60 | |||
| 61 | def test_direct_interp(self): | ||
| 62 | """Lines whose shebang points directly to the interpreter.""" | ||
| 63 | DATA = ( | ||
| 64 | ('#!/foo', '/foo'), | ||
| 65 | ('#! /foo', '/foo'), | ||
| 66 | ('#!/bin/foo ', '/bin/foo'), | ||
| 67 | ('#! /usr/foo ', '/usr/foo'), | ||
| 68 | ('#! /usr/foo -args', '/usr/foo'), | ||
| 69 | ) | ||
| 70 | for shebang, interp in DATA: | ||
| 71 | self.assertEqual(project.RepoHook._ExtractInterpFromShebang(shebang), | ||
| 72 | interp) | ||
| 73 | |||
| 74 | def test_env_interp(self): | ||
| 75 | """Lines whose shebang launches through `env`.""" | ||
| 76 | DATA = ( | ||
| 77 | ('#!/usr/bin/env foo', 'foo'), | ||
| 78 | ('#!/bin/env foo', 'foo'), | ||
| 79 | ('#! /bin/env /bin/foo ', '/bin/foo'), | ||
| 80 | ) | ||
| 81 | for shebang, interp in DATA: | ||
| 82 | self.assertEqual(project.RepoHook._ExtractInterpFromShebang(shebang), | ||
| 83 | interp) | ||
| 84 | |||
| 85 | |||
| 86 | class FakeProject(object): | 47 | class FakeProject(object): |
| 87 | """A fake for Project for basic functionality.""" | 48 | """A fake for Project for basic functionality.""" |
| 88 | 49 | ||
