#include "boost/test/unit_test.hpp"
#include "art/Framework/IO/FileStatsCollector.h"
#include "art/Framework/IO/PostCloseFileRenamer.h"
#include "boost/filesystem.hpp"
#include <sys/stat.h>
#include <unistd.h>
#include <chrono>
#include <thread>
Go to the source code of this file.
#define BOOST_TEST_MODULE (PostCloseFileRenamer_t) |
BOOST_AUTO_TEST_CASE |
( |
constructor |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
testSubstitutions |
| ) |
|
Definition at line 56 of file PostCloseFileRenamer_t.cc.
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);
std::string applySubstitutions(std::string const &filePattern)
BOOST_AUTO_TEST_CASE |
( |
resetFileOpen |
| ) |
|
Definition at line 75 of file PostCloseFileRenamer_t.cc.
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);
BOOST_AUTO_TEST_CASE |
( |
resetEvents |
| ) |
|
Definition at line 88 of file PostCloseFileRenamer_t.cc.
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);
BOOST_AUTO_TEST_CASE |
( |
Runs_subruns |
| ) |
|
Definition at line 105 of file PostCloseFileRenamer_t.cc.
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);
BOOST_AUTO_TEST_CASE |
( |
StartTimesRunsSubruns |
| ) |
|
Definition at line 121 of file PostCloseFileRenamer_t.cc.
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);
BOOST_AUTO_TEST_CASE |
( |
SeqNo1 |
| ) |
|
Definition at line 135 of file PostCloseFileRenamer_t.cc.
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);
BOOST_AUTO_TEST_CASE |
( |
SeqNo2 |
| ) |
|
Definition at line 150 of file PostCloseFileRenamer_t.cc.
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);
BOOST_AUTO_TEST_CASE |
( |
SimpleFileNameSubs |
| ) |
|
Definition at line 161 of file PostCloseFileRenamer_t.cc.
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);
def mkdir(path, mode=0o777)
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE |
( |
SimpleRegex |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
EscapingRegex |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
iFlagRegex |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
gFlagRegex |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
GroupingRegex |
| ) |
|
Definition at line 230 of file PostCloseFileRenamer_t.cc.
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());