from sequana.scripts import coverage
from nose.plugins.attrib import attr
from sequana import sequana_data

#@attr("skip")
class TestPipeline(object):

    @classmethod
    def setup_class(klass):
        """This method is run once for each class before any tests are run"""
        klass.prog = "sequana_coverage"
        klass.params = {'prog': klass.prog}

    @classmethod
    def teardown_class(klass):
        """This method is run once for each class _after_ all tests are run"""
        import os
        # local nosetests execution
        try:os.remove('README')
        except:pass
        try:os.remove('quality.rules')
        except:pass
        try:os.remove('config.yaml')
        except:pass

    def _test_version(self):
        coverage.main([self.prog, '--version'])

    def test_help(self):
        try:
            coverage.main([self.prog, '--help'])
            assert False
        except SystemExit:
            pass
        else:
            raise Exception

    def test_input(self):
        filename = sequana_data('virus.bed', 'data')
        reference = sequana_data('tofill.fa', 'data')
        coverage.main([self.prog, '-i', filename, "-o"]) # "-r", reference])



from sequana.scripts import coverage
from sequana import sequana_data
import pytest

prog = "sequana_coverage"

@pytest.fixture
def coveragefix():
    import os
    # local nosetests execution
    try:os.remove('README')
    except:pass
    try:os.remove('quality.rules')
    except:pass
    try:os.remove('config.yaml')
    except:pass


def test_version():
    try:
        coverage.main([prog, '--version'])
        assert False
    except SystemExit:
        pass
    else:
        raise Exception


def test_help():
    try:
        coverage.main([prog, '--help'])
        assert False
    except SystemExit:
        pass
    else:
        raise Exception


def test_input(tmpdir):

    import os
    directory = tmpdir.mkdir("report")
    name = directory.__str__()

    filename = sequana_data('virus.bed', 'data')
    reference = sequana_data('tofill.fa', 'data')
    coverage.main([prog, '-i', filename, "-o", "--output-directory", name])
    assert os.path.exists(name + os.sep + "coverage_mapping.chrom1.html")

Fix tests to use pytest
Fix tests to use pytest

  from sequana.scripts import coverage
- from nose.plugins.attrib import attr
  from sequana import sequana_data
+ import pytest
  
+ prog = "sequana_coverage"
- #@attr("skip")
- class TestPipeline(object):
  
+ @pytest.fixture
+ def coveragefix():
-     @classmethod
-     def setup_class(klass):
-         """This method is run once for each class before any tests are run"""
-         klass.prog = "sequana_coverage"
-         klass.params = {'prog': klass.prog}
- 
-     @classmethod
-     def teardown_class(klass):
-         """This method is run once for each class _after_ all tests are run"""
-         import os
+     import os
-         # local nosetests execution
+     # local nosetests execution
-         try:os.remove('README')
+     try:os.remove('README')
-         except:pass
+     except:pass
-         try:os.remove('quality.rules')
+     try:os.remove('quality.rules')
-         except:pass
+     except:pass
-         try:os.remove('config.yaml')
+     try:os.remove('config.yaml')
-         except:pass
+     except:pass
- 
-     def _test_version(self):
-         coverage.main([self.prog, '--version'])
- 
-     def test_help(self):
-         try:
-             coverage.main([self.prog, '--help'])
-             assert False
-         except SystemExit:
-             pass
-         else:
-             raise Exception
- 
-     def test_input(self):
-         filename = sequana_data('virus.bed', 'data')
-         reference = sequana_data('tofill.fa', 'data')
-         coverage.main([self.prog, '-i', filename, "-o"]) # "-r", reference])
  
  
+ def test_version():
+     try:
+         coverage.main([prog, '--version'])
+         assert False
+     except SystemExit:
+         pass
+     else:
+         raise Exception
  
+ 
+ def test_help():
+     try:
+         coverage.main([prog, '--help'])
+         assert False
+     except SystemExit:
+         pass
+     else:
+         raise Exception
+ 
+ 
+ def test_input(tmpdir):
+ 
+     import os
+     directory = tmpdir.mkdir("report")
+     name = directory.__str__()
+ 
+     filename = sequana_data('virus.bed', 'data')
+     reference = sequana_data('tofill.fa', 'data')
+     coverage.main([prog, '-i', filename, "-o", "--output-directory", name])
+     assert os.path.exists(name + os.sep + "coverage_mapping.chrom1.html")
+ 
Fix tests to use pytest
## Code Before:
from sequana.scripts import coverage
from nose.plugins.attrib import attr
from sequana import sequana_data

#@attr("skip")
class TestPipeline(object):

    @classmethod
    def setup_class(klass):
        """This method is run once for each class before any tests are run"""
        klass.prog = "sequana_coverage"
        klass.params = {'prog': klass.prog}

    @classmethod
    def teardown_class(klass):
        """This method is run once for each class _after_ all tests are run"""
        import os
        # local nosetests execution
        try:os.remove('README')
        except:pass
        try:os.remove('quality.rules')
        except:pass
        try:os.remove('config.yaml')
        except:pass

    def _test_version(self):
        coverage.main([self.prog, '--version'])

    def test_help(self):
        try:
            coverage.main([self.prog, '--help'])
            assert False
        except SystemExit:
            pass
        else:
            raise Exception

    def test_input(self):
        filename = sequana_data('virus.bed', 'data')
        reference = sequana_data('tofill.fa', 'data')
        coverage.main([self.prog, '-i', filename, "-o"]) # "-r", reference])



## Instruction:
Fix tests to use pytest
## Code After:
from sequana.scripts import coverage
from sequana import sequana_data
import pytest

prog = "sequana_coverage"

@pytest.fixture
def coveragefix():
    import os
    # local nosetests execution
    try:os.remove('README')
    except:pass
    try:os.remove('quality.rules')
    except:pass
    try:os.remove('config.yaml')
    except:pass


def test_version():
    try:
        coverage.main([prog, '--version'])
        assert False
    except SystemExit:
        pass
    else:
        raise Exception


def test_help():
    try:
        coverage.main([prog, '--help'])
        assert False
    except SystemExit:
        pass
    else:
        raise Exception


def test_input(tmpdir):

    import os
    directory = tmpdir.mkdir("report")
    name = directory.__str__()

    filename = sequana_data('virus.bed', 'data')
    reference = sequana_data('tofill.fa', 'data')
    coverage.main([prog, '-i', filename, "-o", "--output-directory", name])
    assert os.path.exists(name + os.sep + "coverage_mapping.chrom1.html")
