1 #define BOOST_TEST_MODULE (PostCloseFileRenamer_t) 2 #include "boost/test/unit_test.hpp" 6 #include "boost/filesystem.hpp" 29 TestFixture::simulateJob()
33 fstats.recordEvent(e1);
34 fstats.recordSubRun(e1.subRunID());
36 std::this_thread::sleep_for(1
s);
38 fstats.recordEvent(e2);
39 fstats.recordSubRun(e2.subRunID());
40 fstats.recordRun(e2.runID());
42 fstats.recordSubRun(
sr);
43 fstats.recordRun(
sr.runID());
44 fstats.recordFileClose();
49 BOOST_FIXTURE_TEST_SUITE(PostCloseFileRenamer_t, TestFixture)
58 std::vector<std::string>
const patterns{
"f/stem_%r_%s_%R_%S.root"s,
61 "f/stem_%5R_%2S.root"s};
62 std::vector<std::string>
const answers{
"f/stem_1_0_2_3.root"s,
65 "f/stem_00002_03.root"s};
68 for (
size_t i{0},
e = patterns.size(); i !=
e; ++i) {
70 auto const& cmp = answers[i];
71 BOOST_TEST(ans == cmp);
80 auto const before = fr.applySubstitutions(
pattern);
81 std::this_thread::sleep_for(1
s);
82 fstats.recordFileOpen();
83 fstats.recordFileClose();
84 auto const after = fr.applySubstitutions(
pattern);
85 BOOST_TEST(before != after);
92 auto const before = fr.applySubstitutions(
pattern);
93 auto const cmp_before =
"-_-_-_-"s;
94 BOOST_TEST(before == cmp_before);
96 auto after = fr.applySubstitutions(
pattern);
97 auto const cmp_after =
"01_00_2_3"s;
98 BOOST_TEST(after == cmp_after);
99 fstats.recordFileOpen();
100 fstats.recordFileClose();
101 after = fr.applySubstitutions(
pattern);
102 BOOST_TEST(after == cmp_before);
110 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"07_-_7_-"s);
112 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"07_00_7_0"s);
114 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"07_00_7_5"s);
116 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"07_00_7_5"s);
118 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"07_00_9_-"s);
124 BOOST_TEST(fr.applySubstitutions(
"%tr") ==
"-"s);
125 BOOST_TEST(fr.applySubstitutions(
"%ts") ==
"-"s);
126 BOOST_TEST(fr.applySubstitutions(
"%tR") ==
"-"s);
127 BOOST_TEST(fr.applySubstitutions(
"%tS") ==
"-"s);
129 BOOST_TEST(fr.applySubstitutions(
"%tr") !=
"-"s);
130 BOOST_TEST(fr.applySubstitutions(
"%ts") !=
"-"s);
131 BOOST_TEST(fr.applySubstitutions(
"%tR") !=
"-"s);
132 BOOST_TEST(fr.applySubstitutions(
"%tS") !=
"-"s);
139 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-00-charlie"s);
140 fstats.recordFileOpen();
141 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-00-charlie"s);
142 fstats.recordFileClose();
143 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-01-charlie"s);
144 fstats.recordFileOpen();
145 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-01-charlie"s);
146 fstats.recordFileClose();
147 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-02-charlie"s);
154 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-00-charlie-0-bertha"s);
155 fstats.recordFileOpen();
156 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-00-charlie-0-bertha"s);
157 fstats.recordFileClose();
158 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"ethel-01-charlie-1-bertha"s);
167 fstats.recordInputFile(
"");
168 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"silly_-_-_-_-_-.root"s);
171 auto owd = boost::filesystem::current_path();
173 boost::filesystem::canonical(boost::filesystem::temp_directory_path())
177 fstats.recordInputFile(
"fileonlynoext");
178 BOOST_TEST(fr.applySubstitutions(
pattern) ==
179 std::string{
"silly_fileonlynoext_" + tmpdir +
"__fileonlynoext_" +
180 tmpdir +
"/fileonlynoext.root"});
183 auto uniqueDir = boost::filesystem::unique_path(
"%%%%-%%%%-%%%%-%%%%");
185 auto absUniqueDir = boost::filesystem::canonical(uniqueDir).native();
186 fstats.recordInputFile((uniqueDir /
"x.ext").native());
187 BOOST_TEST(fr.applySubstitutions(
pattern) ==
188 std::string{
"silly_x_" + absUniqueDir +
"_.ext_x.ext_" +
189 absUniqueDir +
"/x.ext.root"});
193 fstats.recordInputFile(
"/usr/bin/y.ext");
194 BOOST_TEST(fr.applySubstitutions(
pattern) ==
195 "silly_y_/usr/bin_.ext_y.ext_/usr/bin/y.ext.root"s);
202 fstats.recordInputFile(
"/tmp/c.root");
203 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"/tmp/c.dat"s);
210 fstats.recordInputFile(
"/tmp/c.root");
211 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"/tmp/c.dat"s);
218 fstats.recordInputFile(
"/tmp/c.root");
219 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"/tmp/c.dat"s);
226 fstats.recordInputFile(
"/tmp/c.root");
227 BOOST_TEST(fr.applySubstitutions(
pattern) ==
"/tmp/c.rfft"s);
233 auto tmpdir = boost::filesystem::canonical(
"/tmp");
235 fstats.recordInputFile(
"/tmp/c_27_ethel.root");
236 BOOST_TEST(fr.applySubstitutions(
pattern) ==
237 (tmpdir /
"d_27_charlie.root").native());
240 BOOST_AUTO_TEST_SUITE_END()
def mkdir(path, mode=0o777)
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
std::string applySubstitutions(std::string const &filePattern)
static constexpr double sr
BOOST_AUTO_TEST_CASE(constructor)