Better implementation for FileWrapper / DirectoryWrapper.

This commit is contained in:
Mikaël Capelle
2022-05-07 13:58:59 +02:00
parent e204c003ae
commit efaea1edfe
12 changed files with 411 additions and 261 deletions
+5 -5
View File
@@ -11,7 +11,7 @@ else()
set(UIBASE_PATH "${MO2_INSTALL_PATH}/bin")
endif()
add_custom_target(pytest-deps)
add_custom_target(python-tests)
add_test(NAME pytest
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/pylibs/bin/pytest.exe ${CMAKE_CURRENT_SOURCE_DIR} -s
@@ -20,7 +20,7 @@ add_test(NAME pytest
set(extra_paths "${UIBASE_PATH}\\;${MO2_INSTALL_PATH}/bin/dlls")
set_tests_properties(pytest
PROPERTIES
DEPENDS pytest-deps
DEPENDS python-tests
WORKING_DIRECTORY ${MO2_INSTALL_PATH}/bin
ENVIRONMENT_MODIFICATION
"PYTHONPATH=set:${PYLIB_DIR}\\;$<TARGET_FILE_DIR:mobase>;\
@@ -28,10 +28,10 @@ UIBASE_PATH=set:${UIBASE_PATH};\
QT_ROOT=set:${QT_ROOT}"
)
mo2_python_pip_install(pytest-deps
mo2_python_pip_install(python-tests
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pylibs
PACKAGES pytest PyQt6==6.3.0)
add_dependencies(pytest-deps mobase)
add_dependencies(python-tests mobase)
file(GLOB test_files CONFIGURE_DEPENDS "test_*.cpp")
foreach (test_file ${test_files})
@@ -57,5 +57,5 @@ foreach (test_file ${test_files})
target_include_directories(${target}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../mocks)
add_dependencies(pytest-deps ${target})
add_dependencies(python-tests ${target})
endforeach()
+16 -24
View File
@@ -1,34 +1,26 @@
#include "pybind11_utils/arg_wrapper.h"
#include "pybind11_utils/smart_variant_wrapper.h"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <string>
namespace mo2::python::detail {
template <>
struct smart_variant_converter<std::string> {
static std::string from(int const& value) { return std::to_string(value); }
};
template <>
struct smart_variant_converter<int> {
static int from(std::string const& value) { return std::stoi(value); }
};
} // namespace mo2::python::detail
// wrapper that can be constructed from
class Wrapper {
std::string value;
public:
Wrapper() = default;
Wrapper(Wrapper const&) = default;
Wrapper(Wrapper&&) = default;
Wrapper& operator=(Wrapper const&) = default;
Wrapper& operator=(Wrapper&&) = default;
template <class U, std::enable_if_t<std::is_convertible_v<U, std::string>, int> = 0>
Wrapper(U&& u) : value{std::forward<U>(u)}
{
}
Wrapper(int u) : value{std::to_string(u)} {}
operator int() const { return std::stoi(value); }
operator std::string() const { return value; }
};
MO2_PYBIND11_WRAP_ARGUMENT_CASTER(Wrapper, "Wrapper", int, std::string);
using Wrapper = mo2::python::smart_variant<int, std::string>;
template <std::size_t... Is, class Fn>
auto wrap(Fn&& fn)