<commit_before>import os
import unittest

from binstar_client.utils.test.utils import example_path
from ..models import CondaProject, PFile


class CondaProjectTestCase(unittest.TestCase):
    def test_initialize(self):
        cp = CondaProject(example_path('bokeh-apps/weather'))
        self.assertEqual(cp.metadata, {})

        cp = CondaProject(example_path('bokeh-apps/weather'), summary="weather")
        self.assertEqual(cp.metadata, {'summary': 'weather'})

        cp = CondaProject(example_path('bokeh-apps/weather'), description="aa")
        self.assertEqual(cp.metadata, {'description': 'aa'})

    def test_to_stage(self):
        cp = CondaProject(example_path('bokeh-apps/weather'))
        cp.tar_it()
        self.assertEqual(
            cp.to_stage(),
            {'basename': 'weather.tar', 'configuration': {
                'num_of_files': 0, 'size': 10240
            }, 'size': 10240})

    def test_get_project_name_from_file(self):
        prj = CondaProject(example_path('bokeh-apps/timeout.py'))
        self.assertEqual(prj.name, 'timeout')

    def test_get_project_name_from_dir(self):
        prj = CondaProject(example_path('bokeh-apps/weather'))
        self.assertEqual(prj.name, 'weather')

    def test_get_project_name_from_current_dir(self):
        cwd = os.getcwd()
        self.addCleanup(os.chdir, cwd)

        os.chdir(example_path('bokeh-apps/weather'))
        prj = CondaProject('.')
        self.assertEqual(prj.name, 'weather')

    def test_ignore_empty_options(self):
        prj = CondaProject(example_path('bokeh-apps/weather'), version='1')
        self.assertEqual(prj.metadata['version'], '1')
        self.assertNotIn('summary', prj.metadata)
        self.assertNotIn('description', prj.metadata)

    def test_get_file_count_dir(self):
        # Files need to be loaded
        prj = CondaProject(example_path('bokeh-apps/weather'), version='1')
        self.assertEqual(prj.get_file_count(), 0)

    def test_get_file_count_file(self):
        prj = CondaProject(example_path('bokeh-apps/timeout.py'), version='1')
        self.assertEqual(prj.get_file_count(), 1)


class PFileTestCase(unittest.TestCase):
    def test_size(self):
        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        self.assertEqual(pfile.size, 1523)

    def test_basename(self):
        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        self.assertEqual(pfile.basename, 'timeout.py')

    def test_str(self):
        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'),
                      relativepath='bokeh-apps/timeout.py')
        self.assertEqual(str(pfile), "[1523] bokeh-apps/timeout.py")

    def test_validate_with_function(self):
        def function(**kwargs):
            return kwargs['basename'].endswith('.py')

        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        assert pfile.validate(function)

    def test_validate_with_class(self):
        class Validate(object):
            def __init__(self, pfile):
                pass

            def __call__(self):
                return True

        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        assert pfile.validate(Validate)


if __name__ == '__main__':
    unittest.main()
<commit_msg>fix test<commit_after>import os
import unittest

from binstar_client.utils.test.utils import example_path
from binstar_client.utils.projects.models import CondaProject, PFile


class CondaProjectTestCase(unittest.TestCase):
    def test_initialize(self):
        cp = CondaProject(example_path('bokeh-apps/weather'))
        self.assertEqual(cp.metadata, {})

        cp = CondaProject(example_path('bokeh-apps/weather'), summary="weather")
        self.assertEqual(cp.metadata, {'summary': 'weather'})

        cp = CondaProject(example_path('bokeh-apps/weather'), description="aa")
        self.assertEqual(cp.metadata, {'description': 'aa'})

    def test_to_stage(self):
        cp = CondaProject(example_path('bokeh-apps/weather'))
        cp.tar_it()
        self.assertEqual(
            cp.to_stage(),
            {'basename': 'weather.tar', 'configuration': {
                'num_of_files': 0, 'size': 10240
            }})

    def test_get_project_name_from_file(self):
        prj = CondaProject(example_path('bokeh-apps/timeout.py'))
        self.assertEqual(prj.name, 'timeout')

    def test_get_project_name_from_dir(self):
        prj = CondaProject(example_path('bokeh-apps/weather'))
        self.assertEqual(prj.name, 'weather')

    def test_get_project_name_from_current_dir(self):
        cwd = os.getcwd()
        self.addCleanup(os.chdir, cwd)

        os.chdir(example_path('bokeh-apps/weather'))
        prj = CondaProject('.')
        self.assertEqual(prj.name, 'weather')

    def test_ignore_empty_options(self):
        prj = CondaProject(example_path('bokeh-apps/weather'), version='1')
        self.assertEqual(prj.metadata['version'], '1')
        self.assertNotIn('summary', prj.metadata)
        self.assertNotIn('description', prj.metadata)

    def test_get_file_count_dir(self):
        # Files need to be loaded
        prj = CondaProject(example_path('bokeh-apps/weather'), version='1')
        self.assertEqual(prj.get_file_count(), 0)

    def test_get_file_count_file(self):
        prj = CondaProject(example_path('bokeh-apps/timeout.py'), version='1')
        self.assertEqual(prj.get_file_count(), 1)


class PFileTestCase(unittest.TestCase):
    def test_size(self):
        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        self.assertEqual(pfile.size, 1523)

    def test_basename(self):
        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        self.assertEqual(pfile.basename, 'timeout.py')

    def test_str(self):
        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'),
                      relativepath='bokeh-apps/timeout.py')
        self.assertEqual(str(pfile), "[1523] bokeh-apps/timeout.py")

    def test_validate_with_function(self):
        def function(**kwargs):
            return kwargs['basename'].endswith('.py')

        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        assert pfile.validate(function)

    def test_validate_with_class(self):
        class Validate(object):
            def __init__(self, pfile):
                pass

            def __call__(self):
                return True

        pfile = PFile(fullpath=example_path('bokeh-apps/timeout.py'))
        assert pfile.validate(Validate)


if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.13200969990906336, 'fraction_numerical': 0.006820248560169748, 'mean_word_length': 3.121798875702686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7144211', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2072, 'n_words': 305}