2#include <catch2/catch_approx.hpp>
3#include <catch2/catch_test_macros.hpp>
4#include <catch2/matchers/catch_matchers_string.hpp>
7#include "Framework/ConfigurePython.h"
13using Catch::Matchers::ContainsSubstring;
35 CHECK(name ==
"test_instance");
52 CHECK(parameters.getParameter<
int>(
"test_int") == 9);
53 CHECK(parameters.getParameter<
double>(
"test_double") == Approx(7.7));
54 CHECK(parameters.getParameter<std::string>(
"test_string") ==
"Yay!");
59 CHECK(test_dict.getParameter<
int>(
"one") == 1);
60 CHECK(test_dict.getParameter<
double>(
"two") == 2.0);
63 std::vector<int> int_vect{1, 2, 3};
65 parameters.getParameter<std::vector<int>>(
"test_int_vec")};
66 REQUIRE(test_int_vec.size() == int_vect.size());
67 for (std::size_t i{0}; i < test_int_vec.size(); i++)
68 CHECK(test_int_vec.at(i) == int_vect.at(i));
71 std::vector<double> double_vec{0.1, 0.2, 0.3};
73 parameters.getParameter<std::vector<double>>(
"test_double_vec")};
74 REQUIRE(test_double_vec.size() == double_vec.size());
75 for (std::size_t i{0}; i < test_double_vec.size(); i++)
76 CHECK(test_double_vec.at(i) == double_vec.at(i));
79 std::vector<std::string> string_vec{
"first",
"second",
"third"};
81 parameters.getParameter<std::vector<std::string>>(
"test_string_vec")};
82 REQUIRE(test_string_vec.size() == string_vec.size());
83 for (std::size_t i{0}; i < test_string_vec.size(); i++)
84 CHECK(test_string_vec.at(i) == string_vec.at(i));
87 std::vector<std::vector<int>> twod_vec{
88 {11, 12, 13}, {21, 22}, {31, 32, 33, 34}};
90 parameters.getParameter<std::vector<std::vector<int>>>(
"test_2dlist")};
91 REQUIRE(test_2d_vec.size() == twod_vec.size());
92 for (std::size_t i{0}; i < twod_vec.size(); i++) {
93 REQUIRE(test_2d_vec.at(i).size() == twod_vec.at(i).size());
94 for (std::size_t j{0}; j < twod_vec.at(i).size(); j++) {
95 CHECK(test_2d_vec.at(i).at(j) == twod_vec.at(i).at(j));
118TEST_CASE(
"Configure Python Test",
"[Framework][functionality]") {
119 const std::string config_file_name{
"config_python_test_config.py"};
128 SECTION(
"No arguments to python script") {
130 p = cfg.makeProcess();
132 CHECK(p->getPassName() ==
"test");
136 std::ifstream in_file;
137 std::ofstream out_file;
139 in_file.open(config_file_name.c_str(), std::ios::in | std::ios::binary);
141 const std::string config_file_name_arg{
142 "/tmp/config_python_test_config_arg.py"};
143 out_file.open(config_file_name_arg, std::ios::out | std::ios::binary);
144 out_file << in_file.rdbuf();
145 out_file <<
"import sys" << std::endl;
146 out_file <<
"p.logFrequency = int(sys.argv[1])" << std::endl;
153 auto correct_log_freq{9000};
154 SECTION(
"Single argument to python script") {
155 args[0] = (
char *)
"9000";
157 p = cfg.makeProcess();
159 CHECK(p->getLogFrequency() == correct_log_freq);
163 in_file.open(config_file_name.c_str(), std::ios::in | std::ios::binary);
165 out_file.open(config_file_name_arg, std::ios::out | std::ios::binary);
166 out_file << in_file.rdbuf();
167 out_file <<
"p.sequence[0].bad_param = ('tuples','are','not','supported')"
174 SECTION(
"Bad parameter exception test") {
176 std::make_unique<framework::ConfigurePython>(config_file_name_arg, args,
178 ContainsSubstring(
"('tuples', 'are', 'not', 'supported')"));
Base classes for all user event processing components to extend.
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class which represents the process under execution.
Implements an event buffer system for storing event data.
Class which represents the process under execution.
Base class for a module which produces a data product.
Class encapsulating parameters for configuring a processor.
Defines a test Producer to test the passing of configuration variables.
virtual void produce(framework::Event &) override
Process the event and put new data products into it.
TestConfig(const std::string &name, framework::Process &process)
Constructor.
void configure(framework::config::Parameters ¶meters) final override
Configure function.
All classes in the ldmx-sw project use this namespace.
std::unique_ptr< Process > ProcessHandle
A handle to the current process Used to pass a process from ConfigurePython to fire....