blob: a7baf8aa296c9efea10623faea72431aa9b1bd75 [file] [log] [blame]
Alex Klein39701332021-02-24 14:34:58 -07001# Copyright 2021 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""compile_build_api_proto tests."""
6
Alex Klein9ea00b52021-02-24 14:47:22 -07007import os
8
Mike Frysinger2c024062021-05-22 15:43:22 -04009from chromite.third_party.google import protobuf
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040010
Alex Klein39701332021-02-24 14:34:58 -070011from chromite.api import compile_build_api_proto
12
13
14def test_versions_match():
15 """Verify the versions match.
16
17 The protoc version in the compile script needs to be compatible with the
18 version of the library we're using (in chromite/third_party). For now, that
19 means we're checking equality.
20
21 TODO: Investigate whether, e.g. 1.2.0 ~= 1.2.3, and we only need to check the
22 major and minor components.
23 TODO: Investigate using protobuf.__version__ instead of hard coding a version
24 in compile_build_api_proto.
25 """
26 assert compile_build_api_proto.PROTOC_VERSION == protobuf.__version__, (
27 'The protobuf library or compile_build_api_proto.PROTOC_VERSION has been '
28 'updated, but the other has not. They must be updated together.')
Alex Klein9ea00b52021-02-24 14:47:22 -070029
30
31def test_compiles(tmpdir):
32 """Test the script successfully compiles something."""
33 assert not os.listdir(tmpdir)
34 compile_build_api_proto.main(['--destination', str(tmpdir)])
35 # It may produce an __init__.py even if nothing else succeeded, so make sure
36 # we have more than just that.
37 assert len(os.listdir(tmpdir)) > 1