5 # gtk-doc - GTK DocBook documentation generator.
6 # Copyright (C) 2017 Stefan Sauer
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 from gtkdoc
import common
29 class TestUpdateFileIfChanged(unittest
.TestCase
):
31 @mock.patch('os.path.exists')
32 @mock.patch('os.rename')
33 def test_NoOldFile(self
, os_rename
, os_path_exists
):
34 os_path_exists
.return_value
= False
35 res
= common
.UpdateFileIfChanged('/old', '/new', False)
36 os_rename
.assert_called_with('/new', '/old')
39 @mock.patch('os.path.exists')
40 @mock.patch('__builtin__.open', mock
.mock_open(read_data
='bar'))
41 @mock.patch('os.unlink')
42 def test_FilesAreTheSame(self
, os_unlink
, os_path_exists
):
43 os_path_exists
.return_value
= True
44 res
= common
.UpdateFileIfChanged('/old', '/new', False)
45 os_unlink
.assert_called_with('/new')
49 class TestGetModuleDocDir(unittest
.TestCase
):
51 @mock.patch('subprocess.check_output')
52 def test_ReturnsPath(self
, subprocess_check_output
):
53 subprocess_check_output
.return_value
= '/usr'
54 self
.assertEquals(common
.GetModuleDocDir('glib-2.0'), '/usr/share/gtk-doc/html')
57 class TestCreateValidSGMLID(unittest
.TestCase
):
59 def test_AlreadyValid(self
):
60 self
.assertEquals(common
.CreateValidSGMLID('x'), 'x')
62 def test_SpecialCharsBecomeDash(self
):
63 self
.assertEquals(common
.CreateValidSGMLID('x_ y'), 'x--y')
65 def test_SpecialCharsGetRemoved(self
):
66 self
.assertEquals(common
.CreateValidSGMLID('x,;y'), 'xy')
69 if __name__
== '__main__':