Author: gnichols
Date: 2011-01-27 14:32:13 +0000 (Thu, 27 Jan 2011)
New Revision: 738
Added:
trunk/v7/log.py
Log:
589739 - CPUSCALING test includes unprocessed tags around displayed text
Added: trunk/v7/log.py
===================================================================
--- trunk/v7/log.py (rev 0)
+++ trunk/v7/log.py 2011-01-27 14:32:13 UTC (rev 738)
@@ -0,0 +1,65 @@
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Greg Nichols
+
+import sys
+
+class Log(object):
+ def __init__(self, filePath):
+ sys.stdout.flush()
+ self.terminal = sys.stdout
+ self.log = open(filePath, "w")
+ self.log.write("<output>\n")
+
+
+ def write(self, message):
+ self.terminal.write(message)
+ self.log.write(message)
+
+ def logOnly(self, message):
+ self.log.write(message)
+
+ def flush(self):
+ self.terminal.flush()
+
+ def close(self):
+ self.log.write("</output>\n")
+ self.log.close()
+
+def unitTest():
+ print "Creating log qq.txt"
+ log = Log("qq.txt")
+ realStdout = sys.stdout
+ sys.stdout = log
+ print "this should go to both console and log"
+ sys.stdout.flush
+ sys.stdout = realStdout
+ print "this should only go to the console"
+ sys.stdout.flush()
+ log.close()
+ logfile = open("qq.txt", "r")
+ lines = logfile.readlines()
+ if lines[0] == "this should go to both console and log\n":
+ return True
+ else:
+ return False
+
+
+
+if __name__ == "__main__":
+ if not unitTest():
+ print "log.py unit test FAILED"
+ exit(1)
+ print "log.py unit test passed"
+ exit(0)
\ No newline at end of file
Show replies by date