Example #1
0
    def test_by_use_requirements_file_if_both_are_found(self, stdout):
        os.makedirs(self.rel_path("src"))
        self.make_file("src/requirements.txt", "")
        self.make_file("Pipfile.lock", "")

        args = build.parse_args([self.tmpdir, "--inject-build-info"])
        build.build(args)

        self.mock_build_with_pipenv.assert_not_called()
        self.mock_build.assert_called_once()
        self.mock_build.assert_called_with(
            service_name=os.path.basename(self.tmpdir),
            python_version="python27",
            src_dir=self.rel_path("src"),
            requirements_path=self.rel_path("src/requirements.txt"),
            dependencies=[""],
            rebuild=False,
            exclude=None,
            dist_dir=self.rel_path("dist"),
            inject_build_info=True,
        )

        # It creates a few directories...
        self.assertTrue(os.path.exists(self.rel_path("dist")))
        self.assertTrue(os.path.exists(self.rel_path("build_cache")))

        self.assertEqual(
            stdout.getvalue(),
            "Warning- Pipfile and requirements.txt were found. "
            "Using requirements.txt. To use the Pipfile, specify "
            "`--pipfile` or delete the requirements.txt file.\n"
            "{}\n".format(self.rel_path("src/requirements.txt")),
        )
Example #2
0
    def test_build_with_bad_src_directory(self, stdout):
        with self.assertRaises(SystemExit):
            args = build.parse_args([self.tmpdir])
            build.build(args)

        self.mock_build_with_pipenv.assert_not_called()
        self.assertEqual(stdout.getvalue(), "Error: src directory not found!\n")
Example #3
0
    def test_by_default_use_requirements_file(self, stdout):
        os.makedirs(self.rel_path("src"))
        self.make_file("src/requirements.txt", "")

        args = build.parse_args([self.tmpdir])
        build.build(args)

        self.mock_build_with_pipenv.assert_not_called()
        self.mock_build.assert_called_once()
        self.mock_build.assert_called_with(
            service_name=os.path.basename(self.tmpdir),
            python_version="python27",
            src_dir=self.rel_path("src"),
            requirements_path=self.rel_path("src/requirements.txt"),
            dependencies=[""],
            rebuild=False,
            exclude=None,
            dist_dir=self.rel_path("dist"),
            inject_build_info=False,
        )

        # It creates a few directories...
        self.assertTrue(os.path.exists(self.rel_path("dist")))
        self.assertTrue(os.path.exists(self.rel_path("build_cache")))

        self.assertEqual(
            stdout.getvalue(), "{}\n".format(self.rel_path("src/requirements.txt"))
        )
Example #4
0
    def test_use_specified_target_directory(self, stdout):
        os.makedirs(self.rel_path("src"))
        self.make_file("src/requirements.txt", "")

        args = build.parse_args(
            [
                self.tmpdir,
                "--target",
                self.rel_path("crazy-dist"),
                "--exclude",
                "foo",
                "bar",
            ]
        )
        build.build(args)

        self.mock_build_with_pipenv.assert_not_called()
        self.mock_build.assert_called_once()
        self.mock_build.assert_called_with(
            service_name=os.path.basename(self.tmpdir),
            python_version="python27",
            src_dir=self.rel_path("src"),
            requirements_path=self.rel_path("src/requirements.txt"),
            dependencies=[""],
            rebuild=False,
            exclude=["foo", "bar"],
            dist_dir=self.rel_path("crazy-dist"),
            inject_build_info=False,
        )

        # Make sure it creates the path.
        self.assertTrue(os.path.exists(self.rel_path("crazy-dist")))
Example #5
0
    def test_build_with_missing_requirements_file(self, stdout):
        os.makedirs(self.rel_path("src"))
        requirements_file = self.rel_path("src/requirements.txt")
        with self.assertRaises(SystemExit):
            args = build.parse_args([self.tmpdir])
            build.build(args)

        self.assertEqual(
            stdout.getvalue(),
            "{0}\nError: requirements file {0} not found!\n".format(requirements_file),
        )

        self.mock_build_with_pipenv.assert_not_called()
        self.mock_build.assert_not_called()
Example #6
0
    def test_fails_is_pipfile_missing(self, stdout):
        os.makedirs(self.rel_path("src"))

        with self.assertRaises(SystemExit):
            args = build.parse_args(
                [self.tmpdir, "--pipfile", self.rel_path("wacky-pipfile")]
            )
            build.build(args)

        self.assertEqual(
            stdout.getvalue(),
            "{0}\nError: pipfile {0} not found!\n".format(
                self.rel_path("wacky-pipfile")
            ),
        )

        self.mock_build_with_pipenv.assert_not_called()
        self.mock_build.assert_not_called()
Example #7
0
    def test_uses_valid_pipfile_missing(self, stdout):
        os.makedirs(self.rel_path("src"))
        self.make_file("wacky-pipfile", "")

        args = build.parse_args(
            [self.tmpdir, "--pipfile", self.rel_path("wacky-pipfile")]
        )
        build.build(args)

        self.mock_build.assert_not_called()
        self.mock_build_with_pipenv.assert_called_once()
        self.mock_build_with_pipenv.assert_called_with(
            service_name=os.path.basename(self.tmpdir),
            python_version="python27",
            src_dir=self.rel_path("src"),
            pipfile=self.rel_path("wacky-pipfile"),
            dependencies=[""],
            rebuild=False,
            exclude=None,
            dist_dir=self.rel_path("dist"),
            inject_build_info=False,
        )
Example #8
0
    def test_use_specified_requirements_and_pipfile_fails(self, stdout):
        os.makedirs(self.rel_path("src"))
        self.make_file("wacky-requirements.txt", "")

        with self.assertRaises(SystemExit):
            args = build.parse_args(
                [
                    self.tmpdir,
                    "--requirements",
                    self.rel_path("wacky-requirements.txt"),
                    "--pipfile",
                    self.rel_path("wacky-pipfile"),
                ]
            )
            build.build(args)

        self.assertEqual(
            stdout.getvalue(),
            "Error: `requirements` and `pipfile` are mutually " "exclusive\n",
        )

        self.mock_build_with_pipenv.assert_not_called()
        self.mock_build.assert_not_called()