Created
February 10, 2012 22:03
-
-
Save rbrito/1793354 to your computer and use it in GitHub Desktop.
Unittests before changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
import unittest | |
sys.path.append('src') | |
sys.path.append('../src') | |
from common import * | |
class TestCommon(unittest.TestCase): | |
def testTime_Convert(self): | |
EXPECTED_RESULTS = [ | |
(1000, "0:01"), | |
(1000, "0:01"), | |
(1000 * 60, "1:00"), | |
(1000 * 61, "1:01"), | |
(1000 * 70, "1:10"), | |
(1000 * 3599, "59:59"), | |
(1000 * 3600, "1:00:00"), | |
(1000 * 3601, "1:00:01"), | |
(1000 * 3660, "1:01:00"), | |
(1000 * 3661, "1:01:01"), | |
(1000 * 7200, "2:00:00"), | |
("bogus", "bogus"), | |
([], []), | |
] | |
for in_data, expected_data in EXPECTED_RESULTS: | |
actual_data = time_convert(in_data) | |
self.assertEqual(actual_data, expected_data) | |
def testHTML(self): | |
EXPECTED_RESULTS = [ | |
("M&M", "M&M"), | |
("<", "<"), | |
("<", "<"), | |
("dynlists©", "dynlists©"), | |
("dynlists©", "dynlists©"), | |
] | |
for in_data, expected_data in EXPECTED_RESULTS: | |
actual_data = htmlentitydecode(in_data) | |
self.assertEqual(actual_data, expected_data) | |
def testSafeFilename(self): | |
basename = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 $%`-_@{}~!#()." | |
good = "/home/" + basename | |
EXPECTED_RESULTS = [ | |
(("/home/mydirectory/somefile", True), "somefile"), | |
((good, True), good[6:]), | |
] | |
for in_data, expected_data in EXPECTED_RESULTS: | |
actual_data = safeFilename(*in_data) | |
self.assertEqual(actual_data, expected_data) | |
def test_super_unquote(self): | |
EXPECTED_RESULTS = [ | |
('. Automated Testing', '. Automated Testing'), | |
('.%20Automated%20Testing', '. Automated Testing'), | |
('.%2520Automated%2520Testing', '. Automated Testing'), | |
] | |
for in_data, expected_data in EXPECTED_RESULTS: | |
actual_data = super_unquote(in_data) | |
self.assertEqual(actual_data, expected_data) | |
def test_desc(self): | |
EXPECTED_RESULTS = [ | |
(1, '1.0 B'), | |
(512, '512.0 B'), | |
(1023, '1023.0 B'), | |
(1024, '1.0 KB'), | |
(1025, '1.0 KB'), | |
(512 * 1024, '512.0 KB'), | |
(1023 * 1024, '1023.0 KB'), | |
(1024 * 1024, '1.0 MB'), | |
(1025 * 1024, '1.0 MB'), | |
(0.5 * 1024 * 1024 * 1024, '512.0 MB'), | |
(10000000000000000000, "(way too big)"), | |
] | |
for in_data, expected_data in EXPECTED_RESULTS: | |
actual_data = desc(in_data) | |
self.assertEqual(actual_data, expected_data) | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One problem with the code as described here is that it won't give useful fail errors. (Only prints the line in the loop with variables, not the variable values). Apparently you can add message to the assertEquals as the third parameter, which will show the message on failure.