Exemple #1
0
class ProjectPackageDataTests(unittest.TestCase):
    def setUp(self):
        self.project = Project(basedir="/imaginary", name="Unittest")

    def test_should_raise_exception_when_filename_not_given(self):
        self.assertRaises(ValueError, self.project.include_file, "my_package",
                          None)

    def test_should_raise_exception_when_filename_is_empty_string(self):
        self.assertRaises(ValueError, self.project.include_file, "eggs",
                          "\t    \n")

    def test_should_raise_exception_when_package_path_not_given(self):
        self.assertRaises(ValueError, self.project.include_directory, None,
                          "spam")

    def test_should_raise_exception_when_package_path_is_empty_string(self):
        self.assertRaises(ValueError, self.project.include_directory, "\t  \n",
                          "spam")

    def test_should_raise_exception_when_patterns_list_not_given(self):
        self.assertRaises(ValueError, self.project.include_directory, "spam",
                          None)

    def test_should_raise_exception_when_patterns_list_is_empty_list(self):
        self.assertRaises(ValueError, self.project.include_directory, "spam",
                          ["\t   \n"])

    def test_should_package_data_dictionary_is_empty(self):
        self.assertEqual({}, self.project.package_data)

    def test_should_add_filename_to_list_of_included_files_for_package_spam(
            self):
        self.project.include_file("spam", "eggs")

        self.assertEqual({"spam": ["eggs"]}, self.project.package_data)

    def test_should_add_two_filenames_to_list_of_included_files_for_package_spam(
            self):
        self.project.include_file("spam", "eggs")
        self.project.include_file("spam", "ham")

        self.assertEqual({"spam": ["eggs", "ham"]}, self.project.package_data)

    def test_should_add_two_filenames_to_list_of_included_files_for_two_different_packages(
            self):
        self.project.include_file("spam", "eggs")
        self.project.include_file("monty", "ham")

        self.assertEqual({
            "monty": ["ham"],
            "spam": ["eggs"]
        }, self.project.package_data)

    def test_should_add_two_filenames_to_list_of_included_files_and_to_manifest(
            self):
        self.project.include_file("spam", "eggs")
        self.project.include_file("monty", "ham")

        self.assertEqual({
            "monty": ["ham"],
            "spam": ["eggs"]
        }, self.project.package_data)
        self.assertEqual([np("spam/eggs"), np("monty/ham")],
                         self.project.manifest_included_files)

    @patch("pybuilder.core.os.walk")
    def test_should_add_pattern_to_list_of_included_filed_for_package_spam(
            self, walk):
        walk.return_value = [
            [
                jp(self.project.basedir, "spam"), ("foo", "bar"),
                ("bacon.eggs", "bacon.noeggs")
            ],
        ]
        self.project.include_directory("spam", "*.eggs")

        self.assertEqual({"spam": ["bacon.eggs"]}, self.project.package_data)