From 35ae4e4227ebcefcb6c7f4509997a38fbfbd325f Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 31 Mar 2018 11:12:55 +0100 Subject: [PATCH] Issue #160: Add minimize_source testcases --- test.sh | 1 + tests/data/minimize_samples/class.py | 8 +++ tests/data/minimize_samples/class_min.py | 8 +++ tests/data/minimize_samples/comment.py | 2 + tests/data/minimize_samples/comment_min.py | 1 + tests/data/minimize_samples/def.py | 4 ++ tests/data/minimize_samples/def_min.py | 4 ++ tests/data/minimize_samples/hashbang.py | 3 ++ tests/data/minimize_samples/hashbang_min.py | 3 ++ tests/data/minimize_samples/mod.py | 5 ++ tests/data/minimize_samples/mod_min.py | 5 ++ .../data/minimize_samples/obstacle_course.py | 49 +++++++++++++++++++ .../minimize_samples/obstacle_course_min.py | 49 +++++++++++++++++++ tests/data/minimize_samples/pass.py | 1 + tests/data/minimize_samples/pass_min.py | 1 + tests/minimize_source_test.py | 45 +++++++++++++++++ 16 files changed, 189 insertions(+) create mode 100644 tests/data/minimize_samples/class.py create mode 100644 tests/data/minimize_samples/class_min.py create mode 100644 tests/data/minimize_samples/comment.py create mode 100644 tests/data/minimize_samples/comment_min.py create mode 100644 tests/data/minimize_samples/def.py create mode 100644 tests/data/minimize_samples/def_min.py create mode 100644 tests/data/minimize_samples/hashbang.py create mode 100644 tests/data/minimize_samples/hashbang_min.py create mode 100644 tests/data/minimize_samples/mod.py create mode 100644 tests/data/minimize_samples/mod_min.py create mode 100644 tests/data/minimize_samples/obstacle_course.py create mode 100644 tests/data/minimize_samples/obstacle_course_min.py create mode 100644 tests/data/minimize_samples/pass.py create mode 100644 tests/data/minimize_samples/pass_min.py create mode 100644 tests/minimize_source_test.py diff --git a/test.sh b/test.sh index 6e678674..eadd9876 100755 --- a/test.sh +++ b/test.sh @@ -46,6 +46,7 @@ run_test tests/importer_test.py run_test tests/latch_test.py run_test tests/local_test.py run_test tests/master_test.py +run_test tests/minimize_source_tests.py run_test tests/module_finder_test.py run_test tests/nested_test.py run_test tests/parent_test.py diff --git a/tests/data/minimize_samples/class.py b/tests/data/minimize_samples/class.py new file mode 100644 index 00000000..149a5925 --- /dev/null +++ b/tests/data/minimize_samples/class.py @@ -0,0 +1,8 @@ +class C: + """docstring + """ + + def method(self): + """docstring + """ + pass diff --git a/tests/data/minimize_samples/class_min.py b/tests/data/minimize_samples/class_min.py new file mode 100644 index 00000000..e5450b47 --- /dev/null +++ b/tests/data/minimize_samples/class_min.py @@ -0,0 +1,8 @@ +class C: + + + + def method(self): + + + pass diff --git a/tests/data/minimize_samples/comment.py b/tests/data/minimize_samples/comment.py new file mode 100644 index 00000000..9f60ccf2 --- /dev/null +++ b/tests/data/minimize_samples/comment.py @@ -0,0 +1,2 @@ +# comment + # comment diff --git a/tests/data/minimize_samples/comment_min.py b/tests/data/minimize_samples/comment_min.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/data/minimize_samples/comment_min.py @@ -0,0 +1 @@ + diff --git a/tests/data/minimize_samples/def.py b/tests/data/minimize_samples/def.py new file mode 100644 index 00000000..b42a4fdc --- /dev/null +++ b/tests/data/minimize_samples/def.py @@ -0,0 +1,4 @@ +def f(): + """docstring + """ + pass diff --git a/tests/data/minimize_samples/def_min.py b/tests/data/minimize_samples/def_min.py new file mode 100644 index 00000000..02148bba --- /dev/null +++ b/tests/data/minimize_samples/def_min.py @@ -0,0 +1,4 @@ +def f(): + + + pass diff --git a/tests/data/minimize_samples/hashbang.py b/tests/data/minimize_samples/hashbang.py new file mode 100644 index 00000000..0245c48f --- /dev/null +++ b/tests/data/minimize_samples/hashbang.py @@ -0,0 +1,3 @@ +#/usr/bin/python -c +# coding: utf-8 +# comment diff --git a/tests/data/minimize_samples/hashbang_min.py b/tests/data/minimize_samples/hashbang_min.py new file mode 100644 index 00000000..5a74f481 --- /dev/null +++ b/tests/data/minimize_samples/hashbang_min.py @@ -0,0 +1,3 @@ +#/usr/bin/python -c +# coding: utf-8 + diff --git a/tests/data/minimize_samples/mod.py b/tests/data/minimize_samples/mod.py new file mode 100644 index 00000000..6a3fb3cb --- /dev/null +++ b/tests/data/minimize_samples/mod.py @@ -0,0 +1,5 @@ + +"""docstring +""" + +pass diff --git a/tests/data/minimize_samples/mod_min.py b/tests/data/minimize_samples/mod_min.py new file mode 100644 index 00000000..18ef7f86 --- /dev/null +++ b/tests/data/minimize_samples/mod_min.py @@ -0,0 +1,5 @@ + + + + +pass diff --git a/tests/data/minimize_samples/obstacle_course.py b/tests/data/minimize_samples/obstacle_course.py new file mode 100644 index 00000000..c44a55c8 --- /dev/null +++ b/tests/data/minimize_samples/obstacle_course.py @@ -0,0 +1,49 @@ +#!python +# coding : utf-8 +# comment +"docstring" + +import sys + +"cc", {} + +def f1(a, b= None, c=[]): # comment + r"""docstring + """ + x = "" + print( + a, + +b, + """arg1""", # comment +"""arg2""", # comment + c ) + # comment + 'foo' > sys.stderr + "baz" +#comment + sys.stdout;lambda: "justastring" + +1j + +def f2(): + # comment + '''docstring''' + pass +class c: + + u'''docstring''' + + + f='justastring' + b'''docstring +''' +@f1 +class c2(object): + 'docstring' + def __init__(self): + "docstring" + def inner(): pass + d = {'a':0} + for x in '': + "justastring" diff --git a/tests/data/minimize_samples/obstacle_course_min.py b/tests/data/minimize_samples/obstacle_course_min.py new file mode 100644 index 00000000..cee5df60 --- /dev/null +++ b/tests/data/minimize_samples/obstacle_course_min.py @@ -0,0 +1,49 @@ +#!python +# coding : utf-8 + + + +import sys + +"cc", {} + +def f1(a, b= None, c=[]): + + + x = "" + print( + a, + +b, + """arg1""", +"""arg2""", + c ) + + 'foo' > sys.stderr + + + sys.stdout;lambda: "justastring" + +1j + +def f2(): + + + pass +class c: + + + + + f='justastring' + + +@f1 +class c2(object): + + def __init__(self): + + def inner(): pass + d = {'a':0} + for x in '': + "justastring" diff --git a/tests/data/minimize_samples/pass.py b/tests/data/minimize_samples/pass.py new file mode 100644 index 00000000..2ae28399 --- /dev/null +++ b/tests/data/minimize_samples/pass.py @@ -0,0 +1 @@ +pass diff --git a/tests/data/minimize_samples/pass_min.py b/tests/data/minimize_samples/pass_min.py new file mode 100644 index 00000000..2ae28399 --- /dev/null +++ b/tests/data/minimize_samples/pass_min.py @@ -0,0 +1 @@ +pass diff --git a/tests/minimize_source_test.py b/tests/minimize_source_test.py new file mode 100644 index 00000000..3feb5468 --- /dev/null +++ b/tests/minimize_source_test.py @@ -0,0 +1,45 @@ +import unittest2 + +from mitogen.parent import minimize_source + +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): + def test_class(self): + original = read_sample('class.py') + minimized = read_sample('class_min.py') + self.assertEquals(minimized, minimize_source(original)) + + + def test_def(self): + original = read_sample('def.py') + minimized = read_sample('def_min.py') + self.assertEquals(minimized, minimize_source(original)) + + def test_hashbang(self): + original = read_sample('hashbang.py') + minimized = read_sample('hashbang_min.py') + self.assertEquals(minimized, minimize_source(original)) + + def test_mod(self): + original = read_sample('mod.py') + minimized = read_sample('mod_min.py') + self.assertEquals(minimized, minimize_source(original)) + + def test_obstacle_course(self): + original = read_sample('obstacle_course.py') + minimized = read_sample('obstacle_course_min.py') + self.assertEquals(minimized, minimize_source(original)) + + +if __name__ == '__main__': + unittest2.main()