import os

from tvrenamr.cli import helpers

from .base import BaseTest


class TestFrontEnd(BaseTest):
    def setup(self):
        super(TestFrontEnd, self).setup()
        self.config = helpers.get_config()

    def test_passing_current_dir_makes_file_list_a_list(self):
        assert isinstance(helpers.build_file_list([self.files]), list)

    def test_setting_recursive_adds_all_files_below_the_folder(self):
        new_folders = ('herp', 'derp', 'test')
        os.makedirs(os.path.join(self.files, *new_folders))

        def build_folder(folder):
            new_files = ('foo', 'bar', 'blah')
            for fn in new_files:
                with open(os.path.join(self.files, folder, fn), 'w') as f:
                    f.write('')
        build_folder('herp')
        build_folder('herp/derp')
        build_folder('herp/derp/test')
        file_list = helpers.build_file_list([self.files], recursive=True)
        for root, dirs, files in os.walk(self.files):
            for fn in files:
                assert os.path.join(root, fn) in file_list

    def test_ignoring_files(self):
        ignore = self.random_files(self.files)
        file_list = helpers.build_file_list([self.files], ignore_filelist=ignore)
        assert all(fn not in file_list for fn in ignore)

import collections
import os
import sys

from tvrenamr.cli import helpers

from .utils import random_files


def test_passing_current_dir_makes_file_list_a_list(files):
    file_list = helpers.build_file_list([files])

    assert isinstance(file_list, collections.Iterable)

    PY3 = sys.version_info[0] == 3
    string_type = str if PY3 else basestring
    text_type = str if PY3 else unicode
    assert not isinstance(file_list, (string_type, text_type))


def test_setting_recursive_adds_all_files_below_the_folder(files):
    new_folders = ('herp', 'derp', 'test')
    os.makedirs(os.path.join(files, *new_folders))

    def build_folder(folder):
        new_files = ('foo', 'bar', 'blah')
        for fn in new_files:
            with open(os.path.join(files, folder, fn), 'w') as f:
                f.write('')
    build_folder('herp')
    build_folder('herp/derp')
    build_folder('herp/derp/test')
    file_list = helpers.build_file_list([files], recursive=True)
    for root, dirs, files in os.walk(files):
        for fn in files:
            assert (root, fn) in file_list


def test_ignoring_files(files):
    ignore = random_files(files)
    file_list = helpers.build_file_list([files], ignore_filelist=ignore)
    assert all(fn not in file_list for fn in ignore)

Move to function only tests & fix test for generator based build_file_list
Move to function only tests & fix test for generator based build_file_list

build_file_list is a generator now so we need to make sure it returns an
iterable but not a string.

+ import collections
  import os
+ import sys
  
  from tvrenamr.cli import helpers
  
- from .base import BaseTest
+ from .utils import random_files
  
  
+ def test_passing_current_dir_makes_file_list_a_list(files):
+     file_list = helpers.build_file_list([files])
- class TestFrontEnd(BaseTest):
-     def setup(self):
-         super(TestFrontEnd, self).setup()
-         self.config = helpers.get_config()
  
+     assert isinstance(file_list, collections.Iterable)
-     def test_passing_current_dir_makes_file_list_a_list(self):
-         assert isinstance(helpers.build_file_list([self.files]), list)
  
-     def test_setting_recursive_adds_all_files_below_the_folder(self):
-         new_folders = ('herp', 'derp', 'test')
-         os.makedirs(os.path.join(self.files, *new_folders))
+     PY3 = sys.version_info[0] == 3
+     string_type = str if PY3 else basestring
+     text_type = str if PY3 else unicode
+     assert not isinstance(file_list, (string_type, text_type))
  
-         def build_folder(folder):
-             new_files = ('foo', 'bar', 'blah')
-             for fn in new_files:
-                 with open(os.path.join(self.files, folder, fn), 'w') as f:
-                     f.write('')
-         build_folder('herp')
-         build_folder('herp/derp')
-         build_folder('herp/derp/test')
-         file_list = helpers.build_file_list([self.files], recursive=True)
-         for root, dirs, files in os.walk(self.files):
-             for fn in files:
-                 assert os.path.join(root, fn) in file_list
  
+ def test_setting_recursive_adds_all_files_below_the_folder(files):
+     new_folders = ('herp', 'derp', 'test')
+     os.makedirs(os.path.join(files, *new_folders))
-     def test_ignoring_files(self):
-         ignore = self.random_files(self.files)
-         file_list = helpers.build_file_list([self.files], ignore_filelist=ignore)
-         assert all(fn not in file_list for fn in ignore)
  
+     def build_folder(folder):
+         new_files = ('foo', 'bar', 'blah')
+         for fn in new_files:
+             with open(os.path.join(files, folder, fn), 'w') as f:
+                 f.write('')
+     build_folder('herp')
+     build_folder('herp/derp')
+     build_folder('herp/derp/test')
+     file_list = helpers.build_file_list([files], recursive=True)
+     for root, dirs, files in os.walk(files):
+         for fn in files:
+             assert (root, fn) in file_list
+ 
+ 
+ def test_ignoring_files(files):
+     ignore = random_files(files)
+     file_list = helpers.build_file_list([files], ignore_filelist=ignore)
+     assert all(fn not in file_list for fn in ignore)
+ 
Move to function only tests & fix test for generator based build_file_list
## Code Before:
import os

from tvrenamr.cli import helpers

from .base import BaseTest


class TestFrontEnd(BaseTest):
    def setup(self):
        super(TestFrontEnd, self).setup()
        self.config = helpers.get_config()

    def test_passing_current_dir_makes_file_list_a_list(self):
        assert isinstance(helpers.build_file_list([self.files]), list)

    def test_setting_recursive_adds_all_files_below_the_folder(self):
        new_folders = ('herp', 'derp', 'test')
        os.makedirs(os.path.join(self.files, *new_folders))

        def build_folder(folder):
            new_files = ('foo', 'bar', 'blah')
            for fn in new_files:
                with open(os.path.join(self.files, folder, fn), 'w') as f:
                    f.write('')
        build_folder('herp')
        build_folder('herp/derp')
        build_folder('herp/derp/test')
        file_list = helpers.build_file_list([self.files], recursive=True)
        for root, dirs, files in os.walk(self.files):
            for fn in files:
                assert os.path.join(root, fn) in file_list

    def test_ignoring_files(self):
        ignore = self.random_files(self.files)
        file_list = helpers.build_file_list([self.files], ignore_filelist=ignore)
        assert all(fn not in file_list for fn in ignore)

## Instruction:
Move to function only tests & fix test for generator based build_file_list
## Code After:
import collections
import os
import sys

from tvrenamr.cli import helpers

from .utils import random_files


def test_passing_current_dir_makes_file_list_a_list(files):
    file_list = helpers.build_file_list([files])

    assert isinstance(file_list, collections.Iterable)

    PY3 = sys.version_info[0] == 3
    string_type = str if PY3 else basestring
    text_type = str if PY3 else unicode
    assert not isinstance(file_list, (string_type, text_type))


def test_setting_recursive_adds_all_files_below_the_folder(files):
    new_folders = ('herp', 'derp', 'test')
    os.makedirs(os.path.join(files, *new_folders))

    def build_folder(folder):
        new_files = ('foo', 'bar', 'blah')
        for fn in new_files:
            with open(os.path.join(files, folder, fn), 'w') as f:
                f.write('')
    build_folder('herp')
    build_folder('herp/derp')
    build_folder('herp/derp/test')
    file_list = helpers.build_file_list([files], recursive=True)
    for root, dirs, files in os.walk(files):
        for fn in files:
            assert (root, fn) in file_list


def test_ignoring_files(files):
    ignore = random_files(files)
    file_list = helpers.build_file_list([files], ignore_filelist=ignore)
    assert all(fn not in file_list for fn in ignore)
