"""Test code generation command."""
import os
import sys
import textwrap

import py

from pytest_bdd.scripts import main

PATH = os.path.dirname(__file__)


def test_migrate(monkeypatch, capsys, testdir):
    """Test if the code is migrated by a given file mask."""
    tests = testdir.mkpydir('tests')

    tests.join("test_foo.py").write(py.code.Source('''
        """Foo bar tests."""
        from pytest_bdd import scenario

        test_foo = scenario('foo_bar.feature', 'Foo bar')
    '''))

    monkeypatch.setattr(sys, 'argv', ['', 'migrate', tests.strpath])
    main()
    out, err = capsys.readouterr()
    out = sorted(out.splitlines())
    expected = textwrap.dedent('''
    migrated: {0}/test_foo.py
    skipped: {0}/__init__.py
    '''.format(tests.strpath)[1:].replace(u"'", u"'"))
    assert tests.join("test_foo.py").read() == textwrap.dedent('''
    """Foo bar tests."""
    from pytest_bdd import scenario

    @scenario('foo_bar.feature', 'Foo bar')
    def test_foo():
        pass
    ''')

@@ -616,16 +616,26 @@
   out = 
+'%5Cn'.join(
 sorted(o
@@ -650,16 +650,17 @@
 lines())
+)
 %0A    exp
@@ -745,21 +745,16 @@
 nit__.py
-%0A    
 '''.form
@@ -778,29 +778,36 @@
 %5B1:%5D
-.replace(u%22'%22, u%22'%22))
+)%0A    assert out == expected
 %0A   

put assertion back