1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/usr/bin/env python3
# Copyright 2023 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can
# be found in the LICENSE file.
import contextlib
import io
import os
import unittest
from tempfile import TemporaryDirectory
from unittest.mock import patch
from download_profiles import main
class TestDownloadProfiles(unittest.TestCase):
def _test_cmd(self, cmd, exitcode):
out = io.StringIO()
err = io.StringIO()
with self.assertRaises(SystemExit) as se, \
contextlib.redirect_stdout(out), \
contextlib.redirect_stderr(err):
main(cmd)
self.assertEqual(se.exception.code, exitcode)
return out.getvalue(), err.getvalue()
def test_validate_profiles(self):
out, err = self._test_cmd(['validate', '--version', '11.1.0.0'], 0)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 0)
def test_download_profiles(self):
with TemporaryDirectory() as td, \
patch('download_profiles.PGO_PROFILE_DIR', td):
out, err = self._test_cmd(['download', '--version', '11.1.0.0'], 0)
self.assertEqual(len(out), 0)
self.assertEqual(len(err), 0)
self.assertGreater(
len([f for f in os.listdir(td) if f.endswith('.profile')]), 0)
def test_invalid_args(self):
out, err = self._test_cmd(['invalid-action'], 2)
self.assertEqual(len(out), 0)
self.assertGreater(len(err), 0)
def test_invalid_depot_tools_path(self):
out, err = self._test_cmd(
['validate', '--depot-tools', '/no-depot-tools-path'], 3)
self.assertEqual(len(out), 0)
self.assertGreater(len(err), 0)
def test_missing_profiles(self):
out, err = self._test_cmd(['download', '--version', '0.0.0.42'], 4)
self.assertEqual(len(out), 0)
self.assertGreater(len(err), 0)
if __name__ == '__main__':
unittest.main()
|