test_cli.py 1.14 KB
Newer Older
Jgiannelos's avatar
Jgiannelos committed
1
from argparse import Namespace
2
from io import StringIO
Jgiannelos's avatar
Jgiannelos committed
3
4
from unittest import TestCase, mock

5
from wmfmaps.tileset.cli import main
Jgiannelos's avatar
Jgiannelos committed
6
7
8
9
10
11
12
13


class CliTest(TestCase):
    @mock.patch(
        "argparse.ArgumentParser.parse_args",
        return_value=Namespace(tilelist_path="/path/to/tilelist", minzoom=0, maxzoom=1),
    )
    def test_main(self, mock_parse_args):
14
15
16
17
        test_input = "\n".join(["0/0/0", "1/0/0"])
        test_input_file = StringIO()
        test_input_file.write(test_input)
        test_input_file.seek(0)
Jgiannelos's avatar
Jgiannelos committed
18

19
20
21
        with mock.patch(
            "wmfmaps.tileset.cli.argparse.ArgumentParser.parse_args"
        ) as parse_args:
22
23
24
            parse_args.return_value = Namespace(
                tilelist_file=test_input_file, minzoom=0, maxzoom=1
            )
Jgiannelos's avatar
Jgiannelos committed
25
26
27
28
29
30
31
32
33
            with mock.patch("builtins.print") as mock_print:
                main()
                call_list = [
                    mock.call("1/0/1"),
                    mock.call("1/1/0"),
                    mock.call("0/0/0"),
                    mock.call("1/0/0"),
                    mock.call("1/1/1"),
                ]
34
                mock_print.assert_has_calls(call_list, any_order=True)