Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Nektar::MetricPyUnitTest Class Reference

#include <MetricPyUnitTest.h>

Inheritance diagram for Nektar::MetricPyUnitTest:
[legend]

Static Public Member Functions

static MetricSharedPtr create (TiXmlElement *metric, bool generate)
 
- Static Public Member Functions inherited from Nektar::MetricRegex
static MetricSharedPtr create (TiXmlElement *metric, bool generate)
 

Static Public Attributes

static std::string type
 
- Static Public Attributes inherited from Nektar::MetricRegex
static std::string type
 

Protected Member Functions

 MetricPyUnitTest (TiXmlElement *metric, bool generate)
 
void v_Generate (std::istream &pStdout, std::istream &pStderr) override
 Virtual function to generate the metric. Should be redefined in derived classes. More...
 
- Protected Member Functions inherited from Nektar::MetricRegex
 MetricRegex (TiXmlElement *metric, bool generate)
 Constructor. More...
 
bool v_Test (std::istream &pStdout, std::istream &pStderr) override
 Test output against a regex expression and set of matches. More...
 
void v_Generate (std::istream &pStdout, std::istream &pStderr) override
 Test output against a regex expression and set of matches. More...
 
virtual bool v_Test (std::istream &pStdout, std::istream &pStderr)=0
 Virtual function to test the metric. Should be redefined in derived classes. More...
 
virtual void v_Generate (std::istream &pStdout, std::istream &pSrderr)=0
 Virtual function to generate the metric. Should be redefined in derived classes. More...
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::MetricRegex
 ~MetricRegex () override
 
- Public Member Functions inherited from Nektar::Metric
 Metric (TiXmlElement *metric, bool generate)
 Constructor. More...
 
virtual ~Metric ()=default
 
bool Test (std::istream &pStdout, std::istream &pStderr)
 Calls a metric's v_Test function (or v_Generate if m_generate). More...
 
void Generate (std::istream &pStdout, std::istream &pStderr)
 
std::string GetType ()
 Return metric type. More...
 
int GetID ()
 Return metric ID. More...
 
bool SupportsAverage () const
 Return whether this metric supports averaging results from multiple runs. More...
 
- Protected Attributes inherited from Nektar::MetricRegex
std::regex m_regex
 Storage for the boost regex. More...
 
std::vector< std::vector< MetricRegexFieldValue > > m_matches
 Stores the multiple matches defined in each <MATCH> tag. More...
 
bool m_unordered = false
 If true, regex matches may be in any order in output. More...
 
bool m_useStderr = false
 If true, use stderr for testing/generation instead of stdout. More...
 
- Protected Attributes inherited from Nektar::Metric
int m_id
 Stores the ID of this metric. More...
 
std::string m_type
 Stores the type of this metric (uppercase). More...
 
bool m_generate
 Determines whether to generate this metric or not. More...
 
bool m_average = false
 Indicates whether a metric supports averaging results from multiple runs. More...
 
TiXmlElement * m_metric
 Pointer to XML structure containing metric definition. More...
 

Detailed Description

Definition at line 43 of file MetricPyUnitTest.h.

Constructor & Destructor Documentation

◆ MetricPyUnitTest()

Nektar::MetricPyUnitTest::MetricPyUnitTest ( TiXmlElement *  metric,
bool  generate 
)
protected

Definition at line 42 of file MetricPyUnitTest.cpp.

43 : MetricRegex(metric, generate)
44{
45 // Set up the regular expression.
46 m_regex = "^(test.*) \\(.*\\) ... (ERROR|FAIL|ok).*";
47
48 // Python's unittest framework prints to stderr by default.
49 m_useStderr = true;
50
51 // Find the functions to match against.
52 TiXmlElement *func = metric->FirstChildElement("function");
53 ASSERTL0(func || m_generate,
54 "Missing function tag for Python unittest metric!");
55
56 while (func)
57 {
58 ASSERTL0(!EmptyString(func->GetText()),
59 "Missing function name in Python unittest metric.");
60
61 if (!m_generate)
62 {
63 std::vector<MetricRegexFieldValue> tmp(2);
64 tmp[0] = MetricRegexFieldValue(func->GetText());
65 tmp[1] = MetricRegexFieldValue("ok");
66 m_matches.push_back(tmp);
67 }
68
69 func = func->NextSiblingElement("function");
70 }
71}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
bool m_generate
Determines whether to generate this metric or not.
Definition: Metric.h:96
MetricRegex(TiXmlElement *metric, bool generate)
Constructor.
Definition: MetricRegex.cpp:51
std::vector< std::vector< MetricRegexFieldValue > > m_matches
Stores the multiple matches defined in each <MATCH> tag.
Definition: MetricRegex.h:84
bool m_useStderr
If true, use stderr for testing/generation instead of stdout.
Definition: MetricRegex.h:88
std::regex m_regex
Storage for the boost regex.
Definition: MetricRegex.h:82
bool EmptyString(const char *s)
Check to see whether the given string s is empty (or null).
Definition: Metric.h:50

References ASSERTL0, Nektar::EmptyString(), Nektar::Metric::m_generate, Nektar::MetricRegex::m_matches, Nektar::MetricRegex::m_regex, and Nektar::MetricRegex::m_useStderr.

Referenced by create().

Member Function Documentation

◆ create()

static MetricSharedPtr Nektar::MetricPyUnitTest::create ( TiXmlElement *  metric,
bool  generate 
)
inlinestatic

Definition at line 46 of file MetricPyUnitTest.h.

47 {
48 return MetricSharedPtr(new MetricPyUnitTest(metric, generate));
49 }
MetricPyUnitTest(TiXmlElement *metric, bool generate)
std::shared_ptr< Metric > MetricSharedPtr
A shared pointer to an EquationSystem object.
Definition: Metric.h:124

References MetricPyUnitTest().

◆ v_Generate()

void Nektar::MetricPyUnitTest::v_Generate ( std::istream &  pStdout,
std::istream &  pSrderr 
)
overrideprotectedvirtual

Virtual function to generate the metric. Should be redefined in derived classes.

Parameters
pStdoutReference to test output stream.
pSrderrReference to test error stream.

Implements Nektar::Metric.

Definition at line 73 of file MetricPyUnitTest.cpp.

74{
75 // Run MetricRegex to generate matches.
76 MetricRegex::v_Generate(pStdout, pStderr);
77
78 // First remove all existing values.
79 m_metric->Clear();
80
81 // Now create new values.
82 for (int i = 0; i < m_matches.size(); ++i)
83 {
84 ASSERTL0(m_matches[i].size() == 2,
85 "Wrong number of matches for regular expression.");
86 ASSERTL0(m_matches[i][1].m_value == "ok",
87 "Test " + m_matches[i][0].m_value + " has failed");
88
89 TiXmlElement *func = new TiXmlElement("function");
90 func->LinkEndChild(new TiXmlText(m_matches[i][0].m_value));
91 m_metric->LinkEndChild(func);
92 }
93}
TiXmlElement * m_metric
Pointer to XML structure containing metric definition.
Definition: Metric.h:101
void v_Generate(std::istream &pStdout, std::istream &pStderr) override
Test output against a regex expression and set of matches.

References ASSERTL0, Nektar::MetricRegex::m_matches, Nektar::Metric::m_metric, and Nektar::MetricRegex::v_Generate().

Member Data Documentation

◆ type

std::string Nektar::MetricPyUnitTest::type
static
Initial value:
"PYUNITTEST", MetricPyUnitTest::create)
std::string RegisterCreatorFunction(std::string key, CreatorFunction func)
Definition: Metric.h:133
static MetricSharedPtr create(TiXmlElement *metric, bool generate)
MetricFactory & GetMetricFactory()
Definition: Metric.cpp:42

Definition at line 51 of file MetricPyUnitTest.h.