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")), )
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")
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")) )
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")))
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()
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()
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, )
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()