2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
11 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
12 PARENT_DIR
= os
.path
.dirname(SCRIPT_DIR
)
13 CHROME_SRC
= os
.path
.dirname(os
.path
.dirname(os
.path
.dirname(PARENT_DIR
)))
14 MOCK_DIR
= os
.path
.join(CHROME_SRC
, "third_party", "pymock")
16 sys
.path
.append(PARENT_DIR
)
17 sys
.path
.append(MOCK_DIR
)
22 class TestCreateHtml(unittest
.TestCase
):
28 shutil
.rmtree(self
.tempdir
)
30 def testBadInput(self
):
32 self
.assertRaises(create_html
.Error
, create_html
.main
, ['foo.nexe'])
33 # Existing file with wrong extension
34 self
.assertRaises(create_html
.Error
, create_html
.main
, [__file__
])
36 self
.assertRaises(create_html
.Error
, create_html
.main
, [PARENT_DIR
])
38 def testCreatesOutput(self
):
39 self
.tempdir
= tempfile
.mkdtemp("_sdktest")
40 expected_html
= os
.path
.join(self
.tempdir
, 'foo.html')
41 nmf_file
= os
.path
.join(self
.tempdir
, 'foo.nmf')
42 with mock
.patch('sys.stdout'):
43 with mock
.patch('os.path.exists'):
44 with mock
.patch('os.path.isfile'):
45 options
= mock
.MagicMock(return_value
=False)
47 create_html
.CreateHTML([nmf_file
], options
)
48 # Assert that the file was created
49 self
.assertTrue(os
.path
.exists(expected_html
))
50 # Assert that nothing else was created
51 self
.assertEqual(os
.listdir(self
.tempdir
),
52 [os
.path
.basename(expected_html
)])
55 if __name__
== '__main__':