Macros | Functions
PostCloseFileRenamer_t.cc File Reference
#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.

Macros

#define BOOST_TEST_MODULE   (PostCloseFileRenamer_t)
 

Functions

 BOOST_AUTO_TEST_CASE (constructor)
 
 BOOST_AUTO_TEST_CASE (testSubstitutions)
 
 BOOST_AUTO_TEST_CASE (resetFileOpen)
 
 BOOST_AUTO_TEST_CASE (resetEvents)
 
 BOOST_AUTO_TEST_CASE (Runs_subruns)
 
 BOOST_AUTO_TEST_CASE (StartTimesRunsSubruns)
 
 BOOST_AUTO_TEST_CASE (SeqNo1)
 
 BOOST_AUTO_TEST_CASE (SeqNo2)
 
 BOOST_AUTO_TEST_CASE (SimpleFileNameSubs)
 
 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)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (PostCloseFileRenamer_t)

Definition at line 1 of file PostCloseFileRenamer_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( constructor  )

Definition at line 51 of file PostCloseFileRenamer_t.cc.

BOOST_AUTO_TEST_CASE ( testSubstitutions  )

Definition at line 56 of file PostCloseFileRenamer_t.cc.

57 {
58  std::vector<std::string> const patterns{"f/stem_%r_%s_%R_%S.root"s,
59  "f/stem_%l.root"s,
60  "f/stem_%p.root"s,
61  "f/stem_%5R_%2S.root"s};
62  std::vector<std::string> const answers{"f/stem_1_0_2_3.root"s,
63  "f/stem_label.root"s,
64  "f/stem_DEVEL.root"s,
65  "f/stem_00002_03.root"s};
66  simulateJob();
67  PostCloseFileRenamer fr{fstats};
68  for (size_t i{0}, e = patterns.size(); i != e; ++i) {
69  auto const ans = fr.applySubstitutions(patterns[i]);
70  auto const& cmp = answers[i];
71  BOOST_TEST(ans == cmp);
72  }
73 }
const double e
std::string applySubstitutions(std::string const &filePattern)
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( resetFileOpen  )

Definition at line 75 of file PostCloseFileRenamer_t.cc.

76 {
77  simulateJob();
78  PostCloseFileRenamer fr{fstats};
79  std::string const pattern{"%to"};
80  auto const before = fr.applySubstitutions(pattern);
81  std::this_thread::sleep_for(1s);
82  fstats.recordFileOpen();
83  fstats.recordFileClose();
84  auto const after = fr.applySubstitutions(pattern);
85  BOOST_TEST(before != after);
86 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( resetEvents  )

Definition at line 88 of file PostCloseFileRenamer_t.cc.

89 {
90  PostCloseFileRenamer fr{fstats};
91  std::string const pattern{"%02r_%02s_%R_%S"};
92  auto const before = fr.applySubstitutions(pattern);
93  auto const cmp_before = "-_-_-_-"s;
94  BOOST_TEST(before == cmp_before);
95  simulateJob();
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);
103 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( Runs_subruns  )

Definition at line 105 of file PostCloseFileRenamer_t.cc.

106 {
107  std::string const pattern{"%02r_%02s_%R_%S"};
108  PostCloseFileRenamer fr{fstats};
109  fstats.recordRun(art::RunID{7});
110  BOOST_TEST(fr.applySubstitutions(pattern) == "07_-_7_-"s);
111  fstats.recordSubRun(art::SubRunID{7, 0});
112  BOOST_TEST(fr.applySubstitutions(pattern) == "07_00_7_0"s);
113  fstats.recordSubRun(art::SubRunID{7, 5});
114  BOOST_TEST(fr.applySubstitutions(pattern) == "07_00_7_5"s);
115  fstats.recordRun(art::RunID{7});
116  BOOST_TEST(fr.applySubstitutions(pattern) == "07_00_7_5"s);
117  fstats.recordRun(art::RunID{9});
118  BOOST_TEST(fr.applySubstitutions(pattern) == "07_00_9_-"s);
119 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( StartTimesRunsSubruns  )

Definition at line 121 of file PostCloseFileRenamer_t.cc.

122 {
123  PostCloseFileRenamer fr{fstats};
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);
128  simulateJob();
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);
133 }
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( SeqNo1  )

Definition at line 135 of file PostCloseFileRenamer_t.cc.

136 {
137  std::string const pattern{"ethel-%02#-charlie"};
138  PostCloseFileRenamer fr{fstats};
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);
148 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( SeqNo2  )

Definition at line 150 of file PostCloseFileRenamer_t.cc.

151 {
152  std::string const pattern{"ethel-%02#-charlie-%#-bertha"};
153  PostCloseFileRenamer fr{fstats};
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);
159 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( SimpleFileNameSubs  )

Definition at line 161 of file PostCloseFileRenamer_t.cc.

162 {
163  std::string const pattern{"silly_%ifb_%ifd_%ife_%ifn_%ifp.root"};
164  PostCloseFileRenamer fr{fstats};
165 
166  // Empty.
167  fstats.recordInputFile("");
168  BOOST_TEST(fr.applySubstitutions(pattern) == "silly_-_-_-_-_-.root"s);
169 
170  // Simple.
171  auto owd = boost::filesystem::current_path();
172  auto tmpdir =
173  boost::filesystem::canonical(boost::filesystem::temp_directory_path())
174  .native();
175  BOOST_TEST_REQUIRE(chdir(tmpdir.c_str()) == 0);
176 
177  fstats.recordInputFile("fileonlynoext");
178  BOOST_TEST(fr.applySubstitutions(pattern) ==
179  std::string{"silly_fileonlynoext_" + tmpdir + "__fileonlynoext_" +
180  tmpdir + "/fileonlynoext.root"});
181 
182  // Relative.
183  auto uniqueDir = boost::filesystem::unique_path("%%%%-%%%%-%%%%-%%%%");
184  BOOST_TEST_REQUIRE(mkdir(uniqueDir.native().c_str(), 0755) == 0);
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"});
190  BOOST_TEST_REQUIRE(chdir(owd.native().c_str()) == 0);
191 
192  // Absolute.
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);
196 }
def mkdir(path, mode=0o777)
std::string string
Definition: nybbler.cc:12
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( SimpleRegex  )

Definition at line 198 of file PostCloseFileRenamer_t.cc.

199 {
200  std::string const pattern{"%ifs%root%dat%%"};
201  PostCloseFileRenamer fr{fstats};
202  fstats.recordInputFile("/tmp/c.root");
203  BOOST_TEST(fr.applySubstitutions(pattern) == "/tmp/c.dat"s);
204 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( EscapingRegex  )

Definition at line 206 of file PostCloseFileRenamer_t.cc.

207 {
208  std::string const pattern{"%ifs%\\.root%.dat%%"};
209  PostCloseFileRenamer fr{fstats};
210  fstats.recordInputFile("/tmp/c.root");
211  BOOST_TEST(fr.applySubstitutions(pattern) == "/tmp/c.dat"s);
212 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( iFlagRegex  )

Definition at line 214 of file PostCloseFileRenamer_t.cc.

215 {
216  std::string const pattern{"%ifs%ROOT%dat%i%"};
217  PostCloseFileRenamer fr{fstats};
218  fstats.recordInputFile("/tmp/c.root");
219  BOOST_TEST(fr.applySubstitutions(pattern) == "/tmp/c.dat"s);
220 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( gFlagRegex  )

Definition at line 222 of file PostCloseFileRenamer_t.cc.

223 {
224  std::string const pattern{"%ifs%o%f%g%"};
225  PostCloseFileRenamer fr{fstats};
226  fstats.recordInputFile("/tmp/c.root");
227  BOOST_TEST(fr.applySubstitutions(pattern) == "/tmp/c.rfft"s);
228 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( GroupingRegex  )

Definition at line 230 of file PostCloseFileRenamer_t.cc.

231 {
232  std::string const pattern{"%ifd/d_%ifs%^.*?_([\\d]+).*$%${1}_charlie%%%ife"};
233  auto tmpdir = boost::filesystem::canonical("/tmp");
234  PostCloseFileRenamer fr{fstats};
235  fstats.recordInputFile("/tmp/c_27_ethel.root");
236  BOOST_TEST(fr.applySubstitutions(pattern) ==
237  (tmpdir / "d_27_charlie.root").native());
238 }
std::string string
Definition: nybbler.cc:12
std::string pattern
Definition: regex_t.cc:35