Files
ortools-clone/ortools/init/python/init_test.py

55 lines
1.9 KiB
Python
Raw Permalink Normal View History

2022-10-14 17:14:17 +02:00
#!/usr/bin/env python3
2025-01-10 11:35:44 +01:00
# Copyright 2010-2025 Google LLC
2021-11-26 17:36:09 +01:00
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2023-06-27 14:21:34 +02:00
"""Simple unit tests for python/init.swig. Not exhaustive."""
2021-11-26 17:36:09 +01:00
2023-07-02 08:12:09 +02:00
from absl.testing import absltest
from ortools.init.python import init
2021-11-26 17:36:09 +01:00
2022-09-27 18:00:48 +02:00
class InitTest(absltest.TestCase):
2024-03-26 12:33:42 +01:00
2021-11-30 22:37:45 +01:00
def test_logging(self):
2023-06-27 14:21:34 +02:00
print("test_logging")
init.CppBridge.init_logging("pywrapinit_test.py")
init.CppBridge.shutdown_logging()
2021-11-26 17:36:09 +01:00
def test_flags(self):
2023-06-27 14:21:34 +02:00
print("test_cpp_flags")
cpp_flags = init.CppFlags()
2023-06-27 14:21:34 +02:00
assert hasattr(cpp_flags, "stderrthreshold")
assert hasattr(cpp_flags, "log_prefix")
assert hasattr(cpp_flags, "cp_model_dump_prefix")
assert hasattr(cpp_flags, "cp_model_dump_models")
2024-04-08 11:52:13 +02:00
assert hasattr(cpp_flags, "cp_model_dump_submodels")
2023-06-27 14:21:34 +02:00
assert hasattr(cpp_flags, "cp_model_dump_response")
init.CppBridge.set_flags(cpp_flags)
2021-11-26 17:36:09 +01:00
def test_version(self):
2023-06-27 14:21:34 +02:00
print("test_version")
major = init.OrToolsVersion.major_number()
2021-11-30 22:37:45 +01:00
self.assertIsInstance(major, int)
minor = init.OrToolsVersion.minor_number()
2021-11-30 22:37:45 +01:00
self.assertIsInstance(minor, int)
patch = init.OrToolsVersion.patch_number()
2021-11-30 22:37:45 +01:00
self.assertIsInstance(patch, int)
version = init.OrToolsVersion.version_string()
2021-11-30 22:37:45 +01:00
self.assertIsInstance(version, str)
2023-06-27 14:21:34 +02:00
string = f"{major}.{minor}.{patch}"
2021-11-30 22:37:45 +01:00
self.assertEqual(version, string)
2021-11-26 17:36:09 +01:00
2022-09-27 18:00:48 +02:00
2023-06-27 14:21:34 +02:00
if __name__ == "__main__":
2023-07-02 08:12:09 +02:00
absltest.main()