import unittest2

from penchy import util


class TopSortTest(unittest2.TestCase):

    def test_error(self):
        a, b = range(2)
        deps = [(a, b), (b, a)]
        with self.assertRaises(ValueError):
            util.topological_sort([], deps)

    def test_multi_deps(self):
        a, b, c, d = range(4)
        start = [a, b]
        deps = [([a, b], c),
                (c, d)]
        self.assertTrue(util.topological_sort(start, deps) in ([a, b, c, d],
                                                              [b, a, c, d]))

    def test_linear_deps(self):
        a, b, c, d = range(4)
        start = [a]
        deps = [(a, b), (b, c), (c, d)]
        self.assertListEqual(util.topological_sort(start, deps), range(4))


class ClasspathTest(unittest2.TestCase):

    def test_valid_options(self):
        expected = 'foo:bar:baz'
        options = ['-cp', expected]
        self.assertEquals(util.extract_classpath(options), expected)
        expected = 'foo:bar:baz'
        options = ['-classpath', expected]
        self.assertEquals(util.extract_classpath(options), expected)

    def test_multiple_classpaths(self):
        expected = 'foo:bar:baz'
        options = ['-cp', 'com:org:de', '-cp', expected]
        self.assertEquals(util.extract_classpath(options), expected)

    def test_only_option(self):
        options = ['-cp']
        self.assertEquals(util.extract_classpath(options), '')

@@ -94,13 +94,14 @@
 est_
-error
+circle
 (sel
@@ -242,12 +242,8 @@
 ort(
-%5B%5D, 
 deps
@@ -345,16 +345,70 @@
 deps = %5B
+(None, a),%0A                (None, b),%0A                
 (%5Ba, b%5D,
@@ -478,31 +478,24 @@
 ogical_sort(
-start, 
 deps) in (%5Ba
@@ -506,23 +506,16 @@
  c, d%5D,%0A
-       
         
@@ -651,36 +651,27 @@
     
-start = %5Ba%5D%0A        deps = %5B
+deps = %5B(None, a), 
 (a, 
@@ -745,15 +745,8 @@
 ort(
-start, 
 deps

Fix topsort test.