Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172089
Change subject: Add unit tests for `pybal.util.LogFile`
......................................................................
Add unit tests for `pybal.util.LogFile`
Easy.
Change-Id: I1d75808a50f20dba6c8b0ef9f3b674eb3a8b9a66
---
M tests/test_util.py
1 file changed, 43 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal
refs/changes/89/172089/1
diff --git a/tests/test_util.py b/tests/test_util.py
index 993a1bb..ea8d1ff 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -7,11 +7,54 @@
"""
import unittest
+import tempfile
+import os
import pybal
import pybal.util
+class LogFileTestCase(unittest.TestCase):
+ """Test case for `pybal.util.LogFile`."""
+
+ TIMESTAMP_REGEXP = r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+'
+
+ @classmethod
+ def setUpClass(cls):
+ file_handle, cls.path = tempfile.mkstemp('.pybal.test.log')
+ os.close(file_handle)
+
+ @classmethod
+ def tearDownClass(cls):
+ os.unlink(cls.path)
+
+ def setUp(self):
+ self.log_file = pybal.util.LogFile(self.path)
+
+ def tearDown(self):
+ self.log_file.file.close()
+
+ def testWrite(self):
+ """Test `LogFile.write`."""
+ log_lines = ('line 1\n', 'line 2\n', 'line 3\n')
+ self.log_file.write(''.join(log_lines))
+ with open(self.path, 'r') as f:
+ file_lines = f.readlines()
+ self.assertEqual(len(file_lines), 3)
+ for log_line, file_line in zip(log_lines, file_lines):
+ self.assertIn(log_line, file_line)
+ self.assertRegexpMatches(file_line, self.TIMESTAMP_REGEXP)
+
+ def testReopen(self):
+ """Test `LogFile.reopen`."""
+ os.unlink(self.path)
+ self.log_file.reopen()
+ self.log_file.write('test')
+ self.assertTrue(os.path.exists(self.path))
+ with open(self.path, 'r') as f:
+ self.assertIn('test', f.read())
+
+
class ConfigDictTestCase(unittest.TestCase):
"""Test case for `pybal.util.ConfigDict`."""
--
To view, visit https://gerrit.wikimedia.org/r/172089
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d75808a50f20dba6c8b0ef9f3b674eb3a8b9a66
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits