6 from gtkdoc
import common
9 class TestUpdateFileIfChanged(unittest
.TestCase
):
11 @mock.patch('os.path.exists')
12 @mock.patch('os.rename')
13 def test_NoOldFile(self
, os_rename
, os_path_exists
):
14 os_path_exists
.return_value
= False
15 res
= common
.UpdateFileIfChanged('/old', '/new', False)
16 os_rename
.assert_called_with('/new', '/old')
19 @mock.patch('os.path.exists')
20 @mock.patch('__builtin__.open', mock
.mock_open(read_data
='bar'))
21 @mock.patch('os.unlink')
22 def test_FilesAreTheSame(self
, os_unlink
, os_path_exists
):
23 os_path_exists
.return_value
= True
24 res
= common
.UpdateFileIfChanged('/old', '/new', False)
25 os_unlink
.assert_called_with('/new')
29 class TestGetModuleDocDir(unittest
.TestCase
):
31 @mock.patch('subprocess.check_output')
32 def test_ReturnsPath(self
, subprocess_check_output
):
33 subprocess_check_output
.return_value
= '/usr'
34 self
.assertEquals(common
.GetModuleDocDir('glib-2.0'), '/usr/share/gtk-doc/html')
37 class TestCreateValidSGMLID(unittest
.TestCase
):
39 def test_AlreadyValid(self
):
40 self
.assertEquals(common
.CreateValidSGMLID('x'), 'x')
42 def test_SpecialCharsBecomeDash(self
):
43 self
.assertEquals(common
.CreateValidSGMLID('x_ y'), 'x--y')
45 def test_SpecialCharsGetRemoved(self
):
46 self
.assertEquals(common
.CreateValidSGMLID('x,;y'), 'xy')
49 if __name__
== '__main__':