


'''simple docstring'''


import time
from contextlib import contextmanager
from pathlib import Path

import pytest
import requests
from huggingface_hub.hf_api import HfApi, HfFolder


UpperCAmelCase_		:   int							   =		'__DUMMY_TRANSFORMERS_USER__'
UpperCAmelCase_		:   Dict							   =		'Dummy User'
UpperCAmelCase_		:   Union[str, Any]							   =		'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'

UpperCAmelCase_		:   List[Any]							   =		'https://hub-ci.huggingface.co'
UpperCAmelCase_		:   Union[str, Any]							   =		CI_HUB_ENDPOINT + '/datasets/{repo_id}/resolve/{revision}/{path}'
UpperCAmelCase_		:   Optional[int]							   =		CI_HUB_ENDPOINT + '/{repo_id}/resolve/{revision}/{filename}'
UpperCAmelCase_		:   Any							   =		Path('~/.huggingface/hub_ci_token').expanduser()







@pytest.fixture
def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				monkeypatch.setattr(
				    """huggingface_hub.file_download.HUGGINGFACE_CO_URL_TEMPLATE"""							,      SCREAMING_SNAKE_CASE__     )







@pytest.fixture
def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				monkeypatch.setattr("""datasets.config.HF_ENDPOINT"""							,      SCREAMING_SNAKE_CASE__     )
				monkeypatch.setattr("""datasets.config.HUB_DATASETS_URL"""							,      SCREAMING_SNAKE_CASE__     )







@pytest.fixture
def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				monkeypatch.setattr("""huggingface_hub.hf_api.HfFolder.path_token"""							,      SCREAMING_SNAKE_CASE__     )







@pytest.fixture
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				HfFolder.save_token(SCREAMING_SNAKE_CASE__     )
				yield
				HfFolder.delete_token()







@pytest.fixture(scope="""session"""     )
def 			snake_case_   (  ):







				"""simple docstring"""





				return HfApi(endpoint=SCREAMING_SNAKE_CASE__     )







@pytest.fixture(scope="""session"""     )
def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       Optional[int]     		=      HfFolder.get_token()
				HfFolder.save_token(SCREAMING_SNAKE_CASE__     )
				yield CI_HUB_USER_TOKEN
				if previous_token is not None:
								HfFolder.save_token(SCREAMING_SNAKE_CASE__     )







@pytest.fixture
def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				def _cleanup_repo(SCREAMING_SNAKE_CASE__     ):
								hf_api.delete_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""     )

				return _cleanup_repo







@pytest.fixture
def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				@contextmanager
				def _temporary_repo(SCREAMING_SNAKE_CASE__     ):
								try:
												yield repo_id
								finally:
												cleanup_repo(SCREAMING_SNAKE_CASE__     )

				return _temporary_repo







@pytest.fixture(scope="""session"""     )
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      f"""repo_txt_data-{int(time.time() * 10E3     )}"""
				_SCREAMING_SNAKE_CASE :       str     		=      f"""{CI_HUB_USER}/{repo_name}"""
				hf_api.create_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""							,      private=SCREAMING_SNAKE_CASE__     )
				hf_api.upload_file(
				    token=SCREAMING_SNAKE_CASE__							,      path_or_fileobj=str(SCREAMING_SNAKE_CASE__     )							,      path_in_repo="""data/text_data.txt"""							,      repo_id=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""							,      )
				yield repo_id
				try:
								hf_api.delete_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""     )
				except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
								pass







@pytest.fixture()
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				return hf_private_dataset_repo_txt_data_







@pytest.fixture(scope="""session"""     )
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      f"""repo_zipped_txt_data-{int(time.time() * 10E3     )}"""
				_SCREAMING_SNAKE_CASE :       Optional[int]     		=      f"""{CI_HUB_USER}/{repo_name}"""
				hf_api.create_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""							,      private=SCREAMING_SNAKE_CASE__     )
				hf_api.upload_file(
				    token=SCREAMING_SNAKE_CASE__							,      path_or_fileobj=str(SCREAMING_SNAKE_CASE__     )							,      path_in_repo="""data.zip"""							,      repo_id=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""							,      )
				yield repo_id
				try:
								hf_api.delete_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""     )
				except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
								pass







@pytest.fixture()
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				return hf_private_dataset_repo_zipped_txt_data_







@pytest.fixture(scope="""session"""     )
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      f"""repo_zipped_img_data-{int(time.time() * 10E3     )}"""
				_SCREAMING_SNAKE_CASE :       Optional[int]     		=      f"""{CI_HUB_USER}/{repo_name}"""
				hf_api.create_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""							,      private=SCREAMING_SNAKE_CASE__     )
				hf_api.upload_file(
				    token=SCREAMING_SNAKE_CASE__							,      path_or_fileobj=str(SCREAMING_SNAKE_CASE__     )							,      path_in_repo="""data.zip"""							,      repo_id=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""							,      )
				yield repo_id
				try:
								hf_api.delete_repo(SCREAMING_SNAKE_CASE__							,      token=SCREAMING_SNAKE_CASE__							,      repo_type="""dataset"""     )
				except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
								pass







@pytest.fixture()
def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				return hf_private_dataset_repo_zipped_img_data_








'''simple docstring'''


import unittest

from knapsack import greedy_knapsack as kp





class     lowercase__  (						unittest.TestCase					):





							'''simple docstring'''


							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       str     		=      [10, 20, 30, 40, 50, 60]
											_SCREAMING_SNAKE_CASE :       List[str]     		=      [2, 4, 6, 8, 10, 12]
											_SCREAMING_SNAKE_CASE :       str     		=      100
											self.assertEqual(kp.calc_profit(__snake_case    ,					__snake_case    ,					__snake_case  )    ,					210  )






							def UpperCAmelCase_	(    self  ):
											self.assertRaisesRegex(__snake_case    ,					"""max_weight must greater than zero."""  )






							def UpperCAmelCase_	(    self  ):
											self.assertRaisesRegex(__snake_case    ,					"""Weight can not be negative."""  )






							def UpperCAmelCase_	(    self  ):
											self.assertRaisesRegex(__snake_case    ,					"""Profit can not be negative."""  )






							def UpperCAmelCase_	(    self  ):
											self.assertRaisesRegex(__snake_case    ,					"""max_weight must greater than zero."""  )






							def UpperCAmelCase_	(    self  ):
											self.assertRaisesRegex(
											    __snake_case    ,					"""The length of profit and weight must be same."""  )


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




