| OLD | NEW |
| (Empty) |
| 1 # Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions | |
| 5 # are met: | |
| 6 # 1. Redistributions of source code must retain the above copyright | |
| 7 # notice, this list of conditions and the following disclaimer. | |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | |
| 9 # notice, this list of conditions and the following disclaimer in the | |
| 10 # documentation and/or other materials provided with the distribution. | |
| 11 # | |
| 12 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 13 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 14 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 15 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 16 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 17 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 18 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 20 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 | |
| 24 """Unit test for png.py.""" | |
| 25 | |
| 26 import unittest | |
| 27 | |
| 28 from png import PNGChecker | |
| 29 from webkitpy.common.system.filesystem_mock import MockFileSystem | |
| 30 from webkitpy.common.system.systemhost_mock import MockSystemHost | |
| 31 | |
| 32 | |
| 33 class MockSCMDetector(object): | |
| 34 | |
| 35 def __init__(self, scm, prop=None): | |
| 36 self._scm = scm | |
| 37 self._prop = prop | |
| 38 | |
| 39 def display_name(self): | |
| 40 return self._scm | |
| 41 | |
| 42 def propget(self, pname, path): | |
| 43 return self._prop | |
| 44 | |
| 45 | |
| 46 class PNGCheckerTest(unittest.TestCase): | |
| 47 """Tests PNGChecker class.""" | |
| 48 | |
| 49 def test_init(self): | |
| 50 """Test __init__() method.""" | |
| 51 | |
| 52 def mock_handle_style_error(self): | |
| 53 pass | |
| 54 | |
| 55 checker = PNGChecker("test/config", mock_handle_style_error, MockSCMDete
ctor('git'), MockSystemHost()) | |
| 56 self.assertEqual(checker._file_path, "test/config") | |
| 57 self.assertEqual(checker._handle_style_error, mock_handle_style_error) | |
| 58 | |
| 59 def test_check(self): | |
| 60 errors = [] | |
| 61 | |
| 62 def mock_handle_style_error(line_number, category, confidence, message): | |
| 63 error = (line_number, category, confidence, message) | |
| 64 errors.append(error) | |
| 65 | |
| 66 file_path = '' | |
| 67 | |
| 68 fs = MockFileSystem() | |
| 69 | |
| 70 scm = MockSCMDetector('svn') | |
| 71 checker = PNGChecker(file_path, mock_handle_style_error, scm, MockSystem
Host(filesystem=fs)) | |
| 72 checker.check() | |
| 73 self.assertEqual(len(errors), 1) | |
| 74 self.assertEqual(errors[0], | |
| 75 (0, 'image/png', 5, 'Set the svn:mime-type property (s
vn propset svn:mime-type image/png ).')) | |
| 76 | |
| 77 files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.p
ng = svn:mime-type=image/png'} | |
| 78 fs = MockFileSystem(files) | |
| 79 scm = MockSCMDetector('git') | |
| 80 errors = [] | |
| 81 checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemH
ost(os_name='linux', filesystem=fs)) | |
| 82 checker.check() | |
| 83 self.assertEqual(len(errors), 0) | |
| 84 | |
| 85 files = {'/Users/mock/.subversion/config': '#enable-auto-props = yes'} | |
| 86 fs = MockFileSystem(files) | |
| 87 scm = MockSCMDetector('git') | |
| 88 errors = [] | |
| 89 checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemH
ost(os_name='linux', filesystem=fs)) | |
| 90 checker.check() | |
| 91 self.assertEqual(len(errors), 1) | |
| 92 | |
| 93 files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n#en
able-auto-props = yes\n*.png = svn:mime-type=image/png'} | |
| 94 fs = MockFileSystem(files) | |
| 95 scm = MockSCMDetector('git') | |
| 96 errors = [] | |
| 97 checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemH
ost(os_name='linux', filesystem=fs)) | |
| 98 checker.check() | |
| 99 self.assertEqual(len(errors), 0) | |
| 100 | |
| 101 files = {'/Users/mock/.subversion/config': '#enable-auto-props = yes\nen
able-auto-props = yes\n*.png = svn:mime-type=image/png'} | |
| 102 fs = MockFileSystem(files) | |
| 103 scm = MockSCMDetector('git') | |
| 104 errors = [] | |
| 105 checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemH
ost(os_name='linux', filesystem=fs)) | |
| 106 checker.check() | |
| 107 self.assertEqual(len(errors), 0) | |
| 108 | |
| 109 files = {'/Users/mock/.subversion/config': 'enable-auto-props = no'} | |
| 110 fs = MockFileSystem(files) | |
| 111 scm = MockSCMDetector('git') | |
| 112 errors = [] | |
| 113 checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemH
ost(os_name='linux', filesystem=fs)) | |
| 114 checker.check() | |
| 115 self.assertEqual(len(errors), 1) | |
| 116 | |
| 117 file_path = "foo.png" | |
| 118 fs.write_binary_file(file_path, "Dummy binary data") | |
| 119 scm = MockSCMDetector('git') | |
| 120 errors = [] | |
| 121 checker = PNGChecker(file_path, mock_handle_style_error, scm, MockSystem
Host(os_name='linux', filesystem=fs)) | |
| 122 checker.check() | |
| 123 self.assertEqual(len(errors), 1) | |
| 124 | |
| 125 file_path = "foo-expected.png" | |
| 126 fs.write_binary_file(file_path, "Dummy binary data") | |
| 127 scm = MockSCMDetector('git') | |
| 128 errors = [] | |
| 129 checker = PNGChecker(file_path, mock_handle_style_error, scm, MockSystem
Host(os_name='linux', filesystem=fs)) | |
| 130 checker.check() | |
| 131 self.assertEqual(len(errors), 2) | |
| 132 self.assertEqual(errors[0], (0, 'image/png', 5, 'Image lacks a checksum.
Generate pngs using run-webkit-tests to ensure they have a checksum.')) | |
| OLD | NEW |