import os
import pytest
import tempfile

import pandas
from skan import pipe

@pytest.fixture
def image_filename():
    rundir = os.path.abspath(os.path.dirname(__file__))
    datadir = os.path.join(rundir, 'data')
    return os.path.join(datadir, 'retic.tif')


def test_pipe(image_filename):
    data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                               'Scan/PixelHeight')
    assert type(data) == pandas.DataFrame
    assert data.shape[0] > 0


def test_pipe_figure(image_filename):
    with tempfile.TemporaryDirectory() as tempdir:
        data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                                   'Scan/PixelHeight',
                                   save_skeleton='skeleton-plot-',
                                   output_folder=tempdir)
        assert type(data) == pandas.DataFrame
        assert data.shape[0] > 0
        assert os.path.exists(os.path.join(tempdir,
                                           'skeleton-plot-' +
                                           image_filename[:-4] +
                                           '.png'))

import os
import pytest
import tempfile

import pandas
from skan import pipe

@pytest.fixture
def image_filename():
    rundir = os.path.abspath(os.path.dirname(__file__))
    datadir = os.path.join(rundir, 'data')
    return os.path.join(datadir, 'retic.tif')


def test_pipe(image_filename):
    data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                               'Scan/PixelHeight')
    assert type(data) == pandas.DataFrame
    assert data.shape[0] > 0


def test_pipe_figure(image_filename):
    with tempfile.TemporaryDirectory() as tempdir:
        data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                                   'Scan/PixelHeight',
                                   save_skeleton='skeleton-plot-',
                                   output_folder=tempdir)
        assert type(data) == pandas.DataFrame
        assert data.shape[0] > 0
        expected_output = os.path.join(tempdir, 'skeleton-plot-' +
                                       os.path.basename(image_filename)[:-4] +
                                       '.png')
        assert os.path.exists(expected_output)

Fix test for output skeleton plot
Fix test for output skeleton plot

  import os
  import pytest
  import tempfile
  
  import pandas
  from skan import pipe
  
  @pytest.fixture
  def image_filename():
      rundir = os.path.abspath(os.path.dirname(__file__))
      datadir = os.path.join(rundir, 'data')
      return os.path.join(datadir, 'retic.tif')
  
  
  def test_pipe(image_filename):
      data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                                 'Scan/PixelHeight')
      assert type(data) == pandas.DataFrame
      assert data.shape[0] > 0
  
  
  def test_pipe_figure(image_filename):
      with tempfile.TemporaryDirectory() as tempdir:
          data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                                     'Scan/PixelHeight',
                                     save_skeleton='skeleton-plot-',
                                     output_folder=tempdir)
          assert type(data) == pandas.DataFrame
          assert data.shape[0] > 0
+         expected_output = os.path.join(tempdir, 'skeleton-plot-' +
-         assert os.path.exists(os.path.join(tempdir,
-                                            'skeleton-plot-' +
-                                            image_filename[:-4] +
+                                        os.path.basename(image_filename)[:-4] +
-                                            '.png'))
+                                        '.png')
+         assert os.path.exists(expected_output)
  
Fix test for output skeleton plot
## Code Before:
import os
import pytest
import tempfile

import pandas
from skan import pipe

@pytest.fixture
def image_filename():
    rundir = os.path.abspath(os.path.dirname(__file__))
    datadir = os.path.join(rundir, 'data')
    return os.path.join(datadir, 'retic.tif')


def test_pipe(image_filename):
    data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                               'Scan/PixelHeight')
    assert type(data) == pandas.DataFrame
    assert data.shape[0] > 0


def test_pipe_figure(image_filename):
    with tempfile.TemporaryDirectory() as tempdir:
        data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                                   'Scan/PixelHeight',
                                   save_skeleton='skeleton-plot-',
                                   output_folder=tempdir)
        assert type(data) == pandas.DataFrame
        assert data.shape[0] > 0
        assert os.path.exists(os.path.join(tempdir,
                                           'skeleton-plot-' +
                                           image_filename[:-4] +
                                           '.png'))

## Instruction:
Fix test for output skeleton plot
## Code After:
import os
import pytest
import tempfile

import pandas
from skan import pipe

@pytest.fixture
def image_filename():
    rundir = os.path.abspath(os.path.dirname(__file__))
    datadir = os.path.join(rundir, 'data')
    return os.path.join(datadir, 'retic.tif')


def test_pipe(image_filename):
    data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                               'Scan/PixelHeight')
    assert type(data) == pandas.DataFrame
    assert data.shape[0] > 0


def test_pipe_figure(image_filename):
    with tempfile.TemporaryDirectory() as tempdir:
        data = pipe.process_images([image_filename], 'fei', 5e-8, 0.1, 0.075,
                                   'Scan/PixelHeight',
                                   save_skeleton='skeleton-plot-',
                                   output_folder=tempdir)
        assert type(data) == pandas.DataFrame
        assert data.shape[0] > 0
        expected_output = os.path.join(tempdir, 'skeleton-plot-' +
                                       os.path.basename(image_filename)[:-4] +
                                       '.png')
        assert os.path.exists(expected_output)
