import os
import pytest

def sort_list(dic):
    out_list = []

    for key, val in dic.iteritems():
        if "_" not in val:
            out_list.insert(0,key)
        else:
            if val in out_list:
                index = out_list.index(val)
                out_list.insert(index + 1, key)
            else:
                out_list.append(key)
    return out_list



def test_of_sorter():
    dic = {"CONST_A": "CONST_B", "CONST_B": "5", "CONST_C": "4"}
    l = ['CONST_B', 'CONST_A', 'CONST_C']
    assert l == sort_list(dic)

def test_of_sorter_2():
    dic = {"C_A" : "C_B", "C_B" : "C_C", "C_C" : "5"}
    l = ['C_C', 'C_B', 'C_A']

    assert l == sort_list(dic)

def test_of_sorter_3():
    dic = {"C_A1" : "C_B", "C_A2" : "C_B" , "C_B" : "5"}
    l = ['C_B', 'C_A2', 'C_A1']
    assert l == sort_list(dic)

def test_of_sorter_4():
    dic = {"C_C" : "5", "C_B":"C_C", "C_A1":"C_B", "C_A2":"C_B"}
    l = ['C_C', 'C_B', 'C_A2', 'C_A1']
    assert l == sort_list(dic)

def test_of_sorter_5():
    dic = {  "C_C" : "C_A + C_B" , "C_A":"5", "C_B":"3"}
    l = ['C_B', 'C_A', 'C_C']
    assert l == sort_list(dic)

def test_of_sorter_6():
    dic = {  "C_C" : "C_A + C_B" , "C_A":"5", "C_B":"3"}
    l = ['C_B', 'C_A', 'C_C']
    assert l == sort_list(dic)

def test_of_ecev_of_file():
    from dic import dic

    sort = sort_list(dic)

    f = "";

    for x in sort:
        f += x + " = " + dic[x] + "\n"

    try:
        exec f
    except NameError, e:
        pytest.fail(e)


@@ -21,361 +21,48 @@
 est%0A
-%0Adef sort_list(dic):%0A    out_list = %5B%5D%0A%0A    for key, val in dic.iteritems():%0A        if %22_%22 not in val:%0A            out_list.insert(0,key)%0A        else:%0A            if val in out_list:%0A                index = out_list.index(val)%0A                out_list.insert(index + 1, key)%0A            else:%0A                out_list.append(key)%0A    return out_list%0A%0A
+from data_holder import DataHolder as dh
 %0A%0Ade
@@ -196,32 +196,37 @@
     assert l == 
+dh().
 sort_list(dic)%0A%0A
@@ -342,32 +342,37 @@
     assert l == 
+dh().
 sort_list(dic)%0A%0A
@@ -492,32 +492,37 @@
     assert l == 
+dh().
 sort_list(dic)%0A%0A
@@ -657,32 +657,37 @@
     assert l == 
+dh().
 sort_list(dic)%0A%0A
@@ -805,32 +805,37 @@
     assert l == 
+dh().
 sort_list(dic)%0A%0A
@@ -861,34 +861,32 @@
 6():%0A    dic = %7B
-  
 %22C_C%22 : %22C_A + C
@@ -959,16 +959,21 @@
 rt l == 
+dh().
 sort_lis
@@ -1044,16 +1044,21 @@
  sort = 
+dh().
 sort_lis

fix tests