Commit 5c76e6e9bc8cf260cc2f8b2bfcf8e21461c68cae
1 parent
bdaaa8ae
Add tests for logging
Showing
1 changed file
with
93 additions
and
4 deletions
test/test_GApplication.py
| ... | ... | @@ -37,6 +37,9 @@ class Test(GPythonTestSuite): |
| 37 | 37 | # Call base class constructor |
| 38 | 38 | GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | + # Set members | |
| 41 | + self.logfile = "test_logger.log" | |
| 42 | + | |
| 40 | 43 | # Return |
| 41 | 44 | return |
| 42 | 45 | |
| ... | ... | @@ -50,16 +53,102 @@ class Test(GPythonTestSuite): |
| 50 | 53 | self.name("app") |
| 51 | 54 | |
| 52 | 55 | # Append tests |
| 53 | - self.append(self.test, "Application module dummy test") | |
| 56 | + self.append(self.test_log, "Test GLog") | |
| 54 | 57 | |
| 55 | 58 | # Return |
| 56 | 59 | return |
| 57 | 60 | |
| 58 | 61 | |
| 59 | - # Test function | |
| 60 | - def test(self): | |
| 62 | + # Test GLog | |
| 63 | + def test_log(self): | |
| 61 | 64 | """ |
| 62 | - Test function. | |
| 65 | + Test GLog. | |
| 63 | 66 | """ |
| 67 | + # Allocate logger | |
| 68 | + log = GLog(self.logfile, True) | |
| 69 | + | |
| 70 | + # Test print methods | |
| 71 | + log("Test __call__(std::string)") | |
| 72 | + log("\n") | |
| 73 | + log(True) | |
| 74 | + log("\n") | |
| 75 | + log(41) | |
| 76 | + log("\n") | |
| 77 | + log(3.1415) | |
| 78 | + log("\n") | |
| 79 | + log.parformat("This is a parameter") | |
| 80 | + log("\n") | |
| 81 | + log.toupper("upper case") | |
| 82 | + log("\n") | |
| 83 | + log.tolower("LOWER CASE") | |
| 84 | + log("\n") | |
| 85 | + log.fill("Higgs", 3) | |
| 86 | + log("\n") | |
| 87 | + log.left("Left", 10) | |
| 88 | + log("\n") | |
| 89 | + log.right("Right", 10) | |
| 90 | + log("\n") | |
| 91 | + log.center("Center", 10) | |
| 92 | + log("\n") | |
| 93 | + log.header0("Header 0") | |
| 94 | + log("\n") | |
| 95 | + log.header1("Header 1") | |
| 96 | + log.header2("Header 2") | |
| 97 | + log.header3("Header 3") | |
| 98 | + | |
| 99 | + # Close logger | |
| 100 | + log.close() | |
| 101 | + | |
| 102 | + # Set reference | |
| 103 | + ref = [] | |
| 104 | + ref.append("Test __call__(std::string)\n") | |
| 105 | + ref.append("1\n") | |
| 106 | + ref.append("41\n") | |
| 107 | + ref.append("3.1415\n") | |
| 108 | + ref.append(" This is a parameter .......: \n") | |
| 109 | + ref.append("UPPER CASE\n") | |
| 110 | + ref.append("lower case\n") | |
| 111 | + ref.append("HiggsHiggsHiggs\n") | |
| 112 | + ref.append("Left \n") | |
| 113 | + ref.append(" Right\n") | |
| 114 | + ref.append(" Center \n") | |
| 115 | + ref.append("\n") | |
| 116 | + ref.append("+==========+\n") | |
| 117 | + ref.append("| Header 1 |\n") | |
| 118 | + ref.append("+==========+\n") | |
| 119 | + ref.append("+----------+\n") | |
| 120 | + ref.append("| Header 2 |\n") | |
| 121 | + ref.append("+----------+\n") | |
| 122 | + ref.append("=== Header 3 ===\n") | |
| 123 | + | |
| 124 | + # Set calls for error messages | |
| 125 | + calls = [] | |
| 126 | + calls.append("__call__(std::string)") | |
| 127 | + calls.append("__call__(bool)") | |
| 128 | + calls.append("__call__(int)") | |
| 129 | + calls.append("__call__(double)") | |
| 130 | + calls.append("parformat()") | |
| 131 | + calls.append("toupper()") | |
| 132 | + calls.append("tolower()") | |
| 133 | + calls.append("fill()") | |
| 134 | + calls.append("left()") | |
| 135 | + calls.append("right()") | |
| 136 | + calls.append("center()") | |
| 137 | + calls.append("header0()") | |
| 138 | + calls.append("header1()") | |
| 139 | + calls.append("header1()") | |
| 140 | + calls.append("header1()") | |
| 141 | + calls.append("header2()") | |
| 142 | + calls.append("header2()") | |
| 143 | + calls.append("header2()") | |
| 144 | + calls.append("header3()") | |
| 145 | + | |
| 146 | + # Check file | |
| 147 | + file = open(self.logfile, "r") | |
| 148 | + lines = file.readlines() | |
| 149 | + file.close() | |
| 150 | + for i, line in enumerate(lines): | |
| 151 | + self.test_assert(line == ref[i], "Test "+calls[i]) | |
| 152 | + | |
| 64 | 153 | # Return |
| 65 | 154 | return | ... | ... |