Skip to content

Commit 03d8438

Browse files
Holt59mikael-capelle
authored andcommitted
Switch VersionInfo -> Version for ModOrganizer2. (#132)
1 parent 66c1824 commit 03d8438

File tree

4 files changed

+101
-28
lines changed

4 files changed

+101
-28
lines changed

src/mobase/wrappers/basic_classes.cpp

+74-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,69 @@ namespace mo2::python {
3333

3434
void add_versioninfo_classes(py::module_ m)
3535
{
36+
// Version
37+
py::class_<Version> pyVersion(m, "Version");
38+
39+
py::enum_<Version::ReleaseType>(pyVersion, "ReleaseType")
40+
.value("DEVELOPMENT", Version::Development)
41+
.value("ALPHA", Version::Alpha)
42+
.value("BETA", Version::Beta)
43+
.value("RELEASE_CANDIDATE", Version::ReleaseCandidate)
44+
.export_values();
45+
46+
py::enum_<Version::ParseMode>(pyVersion, "ParseMode")
47+
.value("SEMVER", Version::ParseMode::SemVer)
48+
.value("MO2", Version::ParseMode::MO2);
49+
50+
py::enum_<Version::FormatMode>(pyVersion, "FormatMode", py::arithmetic{})
51+
.value("FORCE_SUBPATCH", Version::FormatMode::ForceSubPatch)
52+
.value("NO_SEPARATOR", Version::FormatMode::NoSeparator)
53+
.value("SHORT_ALPHA_BETA", Version::FormatMode::ShortAlphaBeta)
54+
.value("NO_METADATA", Version::FormatMode::NoMetadata)
55+
.value("CONDENSED",
56+
static_cast<Version::FormatMode>(Version::FormatCondensed.toInt()))
57+
.export_values();
58+
59+
pyVersion
60+
.def_static("parse", &Version::parse, "value"_a,
61+
"mode"_a = Version::ParseMode::SemVer)
62+
.def(py::init<int, int, int, QString>(), "major"_a, "minor"_a, "patch"_a,
63+
"metadata"_a = "")
64+
.def(py::init<int, int, int, int, QString>(), "major"_a, "minor"_a,
65+
"patch"_a, "subpatch"_a, "metadata"_a = "")
66+
.def(py::init<int, int, int, Version::ReleaseType, QString>(), "major"_a,
67+
"minor"_a, "patch"_a, "type"_a, "metadata"_a = "")
68+
.def(py::init<int, int, int, int, Version::ReleaseType, QString>(),
69+
"major"_a, "minor"_a, "patch"_a, "subpatch"_a, "type"_a,
70+
"metadata"_a = "")
71+
.def(py::init<int, int, int, Version::ReleaseType, int, QString>(),
72+
"major"_a, "minor"_a, "patch"_a, "type"_a, "prerelease"_a,
73+
"metadata"_a = "")
74+
.def(py::init<int, int, int, int, Version::ReleaseType, int, QString>(),
75+
"major"_a, "minor"_a, "patch"_a, "subpatch"_a, "type"_a,
76+
"prerelease"_a, "metadata"_a = "")
77+
.def(py::init<int, int, int, int,
78+
std::vector<std::variant<int, Version::ReleaseType>>,
79+
QString>(),
80+
"major"_a, "minor"_a, "patch"_a, "subpatch"_a, "prereleases"_a,
81+
"metadata"_a = "")
82+
.def("isPreRelease", &Version::isPreRelease)
83+
.def_property_readonly("major", &Version::major)
84+
.def_property_readonly("minor", &Version::minor)
85+
.def_property_readonly("patch", &Version::patch)
86+
.def_property_readonly("subpatch", &Version::subpatch)
87+
.def_property_readonly("prereleases", &Version::preReleases)
88+
.def_property_readonly("build_metadata", &Version::buildMetadata)
89+
.def("string", &Version::string, "mode"_a = Version::FormatCondensed)
90+
.def("__str__", &Version::string)
91+
.def(py::self < py::self)
92+
.def(py::self > py::self)
93+
.def(py::self <= py::self)
94+
.def(py::self >= py::self)
95+
.def(py::self != py::self)
96+
.def(py::self == py::self);
97+
98+
// VersionInfo
3699
py::enum_<MOBase::VersionInfo::ReleaseType>(m, "ReleaseType")
37100
.value("final", MOBase::VersionInfo::RELEASE_FINAL)
38101
.value("candidate", MOBase::VersionInfo::RELEASE_CANDIDATE)
@@ -451,7 +514,17 @@ namespace mo2::python {
451514
.def("overwritePath", &IOrganizer::overwritePath)
452515
.def("basePath", &IOrganizer::basePath)
453516
.def("modsPath", &IOrganizer::modsPath)
454-
.def("appVersion", &IOrganizer::appVersion)
517+
.def("appVersion",
518+
[](IOrganizer& o) {
519+
mo2::python::show_deprecation_warning(
520+
"appVersion", "IOrganizer::appVersion() is deprecated, use "
521+
"IOrganizer::version() instead.");
522+
#pragma warning(push)
523+
#pragma warning(disable : 4996)
524+
return o.appVersion();
525+
#pragma warning(pop)
526+
})
527+
.def("version", &IOrganizer::version)
455528
.def("createMod", &IOrganizer::createMod,
456529
py::return_value_policy::reference, "name"_a)
457530
.def("getGame", &IOrganizer::getGame, py::return_value_policy::reference,

tests/mocks/MockOrganizer.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MockOrganizer : public IOrganizer {
1414
MOCK_METHOD(QString, basePath, (), (const, override));
1515
MOCK_METHOD(QString, modsPath, (), (const, override));
1616
MOCK_METHOD(VersionInfo, appVersion, (), (const, override));
17+
MOCK_METHOD(Version, version, (), (const, override));
1718
MOCK_METHOD(IModInterface*, createMod, (GuessedValue<QString> &name), (override));
1819
MOCK_METHOD(IPluginGame*, getGame, (const QString &gameName), (const, override));
1920
MOCK_METHOD(void, modDataChanged, (IModInterface *mod), (override));

tests/python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ foreach (test_file ${test_files})
5353
pybind11_add_module(${target} EXCLUDE_FROM_ALL THIN_LTO ${test_file})
5454
set_target_properties(${target}
5555
PROPERTIES
56+
CXX_STANDARD 20
5657
OUTPUT_NAME ${pymodule}
5758
FOLDER tests/python
5859
LIBRARY_OUTPUT_DIRECTORY "${PYLIB_DIR}/mobase_tests")

tests/python/test_organizer.cpp

+25-27
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,30 @@ PYBIND11_MODULE(organizer, m)
1717
using ::testing::Eq;
1818
using ::testing::Return;
1919

20-
m.def(
21-
"organizer",
22-
[]() -> IOrganizer* {
23-
MockOrganizer* mock = new NiceMock<MockOrganizer>();
24-
ON_CALL(*mock, profileName).WillByDefault([&mock]() {
25-
return "profile";
20+
m.def("organizer", []() -> IOrganizer* {
21+
MockOrganizer* mock = new NiceMock<MockOrganizer>();
22+
ON_CALL(*mock, profileName).WillByDefault([&mock]() {
23+
return "profile";
24+
});
25+
26+
const auto handle = (HANDLE)std::uintptr_t{4654};
27+
ON_CALL(*mock, startApplication)
28+
.WillByDefault([handle](const auto& name, auto&&... args) {
29+
return name == "valid.exe" ? handle : INVALID_HANDLE_VALUE;
30+
});
31+
ON_CALL(*mock, waitForApplication)
32+
.WillByDefault([&mock, original_handle = handle](HANDLE handle, bool,
33+
LPDWORD exitCode) {
34+
if (handle == original_handle) {
35+
*exitCode = 0;
36+
return true;
37+
}
38+
else {
39+
*exitCode = static_cast<DWORD>(-1);
40+
return false;
41+
}
2642
});
27-
const auto handle = (HANDLE)std::uintptr_t{4654};
28-
EXPECT_CALL(*mock, startApplication(Eq("valid.exe"), _, _, _, _, _))
29-
.WillRepeatedly(Return(handle));
30-
EXPECT_CALL(*mock, startApplication(Eq("invalid.exe"), _, _, _, _, _))
31-
.WillRepeatedly(Return(INVALID_HANDLE_VALUE));
32-
ON_CALL(*mock, waitForApplication)
33-
.WillByDefault([&mock, original_handle = handle](HANDLE handle, bool,
34-
LPDWORD exitCode) {
35-
if (handle == original_handle) {
36-
*exitCode = 0;
37-
return true;
38-
}
39-
else {
40-
*exitCode = static_cast<DWORD>(-1);
41-
return false;
42-
}
43-
});
44-
45-
return mock;
46-
},
47-
py::return_value_policy::take_ownership);
43+
44+
return mock;
45+
});
4846
}

0 commit comments

Comments
 (0)