from sequana import vcf_filter
from . import data
pathdata = data.__path__[0]
from easydev import TempFile
import os
import filecmp


def test_vcf_filter():
    ft = TempFile()
    vcf_output_expected = pathdata + os.sep + "vcf_filter_output.vcf"
    vcf_record = vcf_filter.VCF(pathdata + os.sep + "vcf_filter_input.vcf")
    filter_dict = {"QUAL": 10000, "FREQ": 0.85, "INFO": {"DP": ">10",
                                                        "AO": ">200",
                                                        "SRP": "<100"}}
    vcf_record.filter_vcf(filter_dict, ft.name)
    compare_file = filecmp.cmp(ft.name, vcf_output_expected)
    assert compare_file == True
    ft.delete()


def test_constructor():
    vcf = vcf_filter.VCF('dummy')
    

def test_special_cases():
    from sequana import sequana_data
    data = sequana_data("test.vcf", "testing")
   

    # Test the different filter comparisons (< <=, >, >=)
    vcf = vcf_filter.VCF(data)
    filter_dict = {"QUAL": 10000, "FREQ": 0.5, 
             "INFO": {"DP": ">=10", "AO": ">200", "SRP": "<=100"}}
    for variant in vcf:
        vcf._filter_line(variant, filter_dict)

    # WRONG/MISSONG key in the filter INFO 
    vcf = vcf_filter.VCF(data)
    filter_dict = {"QUAL": 10000, "FREQ": 0.1, 
             "INFO": {"DP": ">=10", "AO": ">200", "DUMMY": "<=0"}}
    try:
        for variant in vcf:
            vcf._filter_line(variant, filter_dict)
        assert False
    except:
        assert True

    vcf = vcf_filter.VCF(data)
    filter_dict = {"QUAL": 10000, "FREQ": 0.5, 
             "INFO": {"DP": "<=10"}}
    for variant in vcf:
        vcf._filter_line(variant, filter_dict)

@@ -1,28 +1,83 @@
+import os%0Aimport filecmp%0A%0Afrom easydev import TempFile%0A
 from sequana import vcf_filt
@@ -130,62 +130,8 @@
 %5B0%5D%0A
-from easydev import TempFile%0Aimport os%0Aimport filecmp%0A
 %0A%0Ade
@@ -341,165 +341,128 @@
 = %7B%22
-QUAL%22: 10000, %22FREQ%22: 0.85, %22INFO%22: %7B%22DP%22: %22%3E10%22,%0A                                                        %22AO%22: %22%3E200%22,%0A                                     
+freebayes_score%22: 10000, %22frequency%22: 0.85,%0A                   %22min_depth%22: 10, %22forward_depth%22: 3, %22reverse_depth%22: 3,%0A
     
@@ -481,21 +481,26 @@
    %22
-SRP%22: %22%3C100%22%7D
+strand_ratio%22: 0.2
 %7D%0A  
@@ -633,16 +633,8 @@
 file
- == True
 %0A   
@@ -671,30 +671,24 @@
 uctor():%0A   
- vcf =
  vcf_filter.
@@ -704,920 +704,4 @@
 y')%0A
-    %0A%0Adef test_special_cases():%0A    from sequana import sequana_data%0A    data = sequana_data(%22test.vcf%22, %22testing%22)%0A   %0A%0A    # Test the different filter comparisons (%3C %3C=, %3E, %3E=)%0A    vcf = vcf_filter.VCF(data)%0A    filter_dict = %7B%22QUAL%22: 10000, %22FREQ%22: 0.5, %0A             %22INFO%22: %7B%22DP%22: %22%3E=10%22, %22AO%22: %22%3E200%22, %22SRP%22: %22%3C=100%22%7D%7D%0A    for variant in vcf:%0A        vcf._filter_line(variant, filter_dict)%0A%0A    # WRONG/MISSONG key in the filter INFO %0A    vcf = vcf_filter.VCF(data)%0A    filter_dict = %7B%22QUAL%22: 10000, %22FREQ%22: 0.1, %0A             %22INFO%22: %7B%22DP%22: %22%3E=10%22, %22AO%22: %22%3E200%22, %22DUMMY%22: %22%3C=0%22%7D%7D%0A    try:%0A        for variant in vcf:%0A            vcf._filter_line(variant, filter_dict)%0A        assert False%0A    except:%0A        assert True%0A%0A    vcf = vcf_filter.VCF(data)%0A    filter_dict = %7B%22QUAL%22: 10000, %22FREQ%22: 0.5, %0A             %22INFO%22: %7B%22DP%22: %22%3C=10%22%7D%7D%0A    for variant in vcf:%0A        vcf._filter_line(variant, filter_dict)%0A

fix test