2018-03-31 10:12:55 +00:00
|
|
|
import unittest2
|
|
|
|
|
2018-05-29 12:44:04 +00:00
|
|
|
import mitogen.minify
|
2018-03-31 10:12:55 +00:00
|
|
|
import testlib
|
|
|
|
|
|
|
|
|
|
|
|
def read_sample(fname):
|
|
|
|
sample_path = testlib.data_path('minimize_samples/' + fname)
|
|
|
|
sample_file = open(sample_path)
|
|
|
|
sample = sample_file.read()
|
|
|
|
sample_file.close()
|
|
|
|
return sample
|
|
|
|
|
|
|
|
|
|
|
|
class MinimizeSource(unittest2.TestCase):
|
2018-05-29 12:44:04 +00:00
|
|
|
func = staticmethod(mitogen.minify.minimize_source)
|
|
|
|
|
2018-03-31 10:12:55 +00:00
|
|
|
def test_class(self):
|
|
|
|
original = read_sample('class.py')
|
2018-03-31 11:51:42 +00:00
|
|
|
expected = read_sample('class_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 10:12:55 +00:00
|
|
|
|
2018-03-31 11:51:42 +00:00
|
|
|
def test_comment(self):
|
|
|
|
original = read_sample('comment.py')
|
|
|
|
expected = read_sample('comment_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 10:12:55 +00:00
|
|
|
|
|
|
|
def test_def(self):
|
|
|
|
original = read_sample('def.py')
|
2018-03-31 11:51:42 +00:00
|
|
|
expected = read_sample('def_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 10:12:55 +00:00
|
|
|
|
|
|
|
def test_hashbang(self):
|
|
|
|
original = read_sample('hashbang.py')
|
2018-03-31 11:51:42 +00:00
|
|
|
expected = read_sample('hashbang_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 10:12:55 +00:00
|
|
|
|
|
|
|
def test_mod(self):
|
|
|
|
original = read_sample('mod.py')
|
2018-03-31 11:51:42 +00:00
|
|
|
expected = read_sample('mod_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 11:51:42 +00:00
|
|
|
|
|
|
|
def test_pass(self):
|
|
|
|
original = read_sample('pass.py')
|
|
|
|
expected = read_sample('pass_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 10:12:55 +00:00
|
|
|
|
|
|
|
def test_obstacle_course(self):
|
|
|
|
original = read_sample('obstacle_course.py')
|
2018-03-31 11:51:42 +00:00
|
|
|
expected = read_sample('obstacle_course_min.py')
|
2018-05-29 12:44:04 +00:00
|
|
|
self.assertEqual(expected, self.func(original))
|
2018-03-31 10:12:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest2.main()
|