






import shutil
import tempfile
import unittest
from unittest.mock import patch

from transformers import (
    DefaultFlowCallback,
    IntervalStrategy,
    PrinterCallback,
    ProgressCallback,
    Trainer,
    TrainerCallback,
    TrainingArguments,
    is_torch_available,
)
from transformers.testing_utils import require_torch


if is_torch_available():
					from transformers.trainer import DEFAULT_CALLBACKS

					from .test_trainer import RegressionDataset, RegressionModelConfig, RegressionPreTrainedModel


class       __SCREAMING_SNAKE_CASE   (				__lowercase):






						def __init__(		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  []






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_init_end'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_train_begin'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_train_end'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_epoch_begin'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_epoch_end'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_step_begin'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_step_end'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_evaluate'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_predict'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_save'				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_log'				)







						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






												"""simple docstring"""
												self.events.append('on_prediction_step'				)




@require_torch
class       __SCREAMING_SNAKE_CASE   (				unittest.TestCase):






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  tempfile.mkdtemp()






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												shutil.rmtree(self.output_dir				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase=0       ,  _UpperCamelCase=0       ,  _UpperCamelCase=64       ,  _UpperCamelCase=64       ,  _UpperCamelCase=None       ,  _UpperCamelCase=False       ,  **_UpperCamelCase				):






												"""simple docstring"""
												# disable_tqdm in TrainingArguments has a flaky default since it depends on the level of logging. We make sure
												# its set to False since the tests later on depend on its value.
												lowerCAmelCase__        =  RegressionDataset(length=_UpperCamelCase				)
												lowerCAmelCase__        =  RegressionDataset(length=_UpperCamelCase				)
												lowerCAmelCase__        =  RegressionModelConfig(a=_UpperCamelCase       ,  b=_UpperCamelCase				)
												lowerCAmelCase__        =  RegressionPreTrainedModel(_UpperCamelCase				)

												lowerCAmelCase__        =  TrainingArguments(self.output_dir       ,  disable_tqdm=_UpperCamelCase       ,  report_to=[]       ,  **_UpperCamelCase				)
												return Trainer(
												    _UpperCamelCase       ,  _UpperCamelCase       ,  train_dataset=_UpperCamelCase       ,  eval_dataset=_UpperCamelCase       ,  callbacks=_UpperCamelCase       ,  )






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase       ,  _UpperCamelCase				):






												"""simple docstring"""
												self.assertEqual(len(_UpperCamelCase				)       ,  len(_UpperCamelCase				)				)

												# Order doesn't matter
												lowerCAmelCase__        =  sorted(_UpperCamelCase       ,  key=lambda _UpperCamelCase				: cb.__name__ if isinstance(_UpperCamelCase       ,  _UpperCamelCase				) else cb.__class__.__name__				)
												lowerCAmelCase__        =  sorted(_UpperCamelCase       ,  key=lambda _UpperCamelCase				: cb.__name__ if isinstance(_UpperCamelCase       ,  _UpperCamelCase				) else cb.__class__.__name__				)

												for cba, cba in zip(_UpperCamelCase       ,  _UpperCamelCase				):
																		if isinstance(_UpperCamelCase       ,  _UpperCamelCase				) and isinstance(_UpperCamelCase       ,  _UpperCamelCase				):
																								self.assertEqual(_UpperCamelCase       ,  _UpperCamelCase				)
																		elif isinstance(_UpperCamelCase       ,  _UpperCamelCase				) and not isinstance(_UpperCamelCase       ,  _UpperCamelCase				):
																								self.assertEqual(_UpperCamelCase       ,  cba.__class__				)
																		elif not isinstance(_UpperCamelCase       ,  _UpperCamelCase				) and isinstance(_UpperCamelCase       ,  _UpperCamelCase				):
																								self.assertEqual(cba.__class__       ,  _UpperCamelCase				)
																		else:
																								self.assertEqual(_UpperCamelCase       ,  _UpperCamelCase				)






						def  UpperCamelCase__ (		self       ,  _UpperCamelCase				):






												"""simple docstring"""
												lowerCAmelCase__        =  ['on_init_end', 'on_train_begin']
												lowerCAmelCase__        =  0
												lowerCAmelCase__        =  len(trainer.get_eval_dataloader()				)
												lowerCAmelCase__        =  ['on_prediction_step'] * len(trainer.get_eval_dataloader()				) + ['on_log', 'on_evaluate']
												for _ in range(trainer.state.num_train_epochs				):
																		expected_events.append('on_epoch_begin'				)
																		for _ in range(_UpperCamelCase				):
																								step += 1
																								expected_events += ["on_step_begin", "on_step_end"]
																								if step % trainer.args.logging_steps == 0:
																														expected_events.append('on_log'				)
																								if trainer.args.evaluation_strategy == IntervalStrategy.STEPS and step % trainer.args.eval_steps == 0:
																														expected_events += evaluation_events.copy()
																								if step % trainer.args.save_steps == 0:
																														expected_events.append('on_save'				)
																		expected_events.append('on_epoch_end'				)
																		if trainer.args.evaluation_strategy == IntervalStrategy.EPOCH:
																								expected_events += evaluation_events.copy()
												expected_events += ["on_log", "on_train_end"]
												return expected_events






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  self.get_trainer()
												lowerCAmelCase__        =  DEFAULT_CALLBACKS.copy() + [ProgressCallback]
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												# Callbacks passed at init are added to the default callbacks
												lowerCAmelCase__        =  self.get_trainer(callbacks=[MyTestTrainerCallback]				)
												expected_callbacks.append(_UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												# TrainingArguments.disable_tqdm controls if use ProgressCallback or PrinterCallback
												lowerCAmelCase__        =  self.get_trainer(disable_tqdm=_UpperCamelCase				)
												lowerCAmelCase__        =  DEFAULT_CALLBACKS.copy() + [PrinterCallback]
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)






						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												lowerCAmelCase__        =  DEFAULT_CALLBACKS.copy() + [ProgressCallback]
												lowerCAmelCase__        =  self.get_trainer()

												# We can add, pop, or remove by class name
												trainer.remove_callback(_UpperCamelCase				)
												expected_callbacks.remove(_UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												lowerCAmelCase__        =  self.get_trainer()
												lowerCAmelCase__        =  trainer.pop_callback(_UpperCamelCase				)
												self.assertEqual(cb.__class__       ,  _UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												trainer.add_callback(_UpperCamelCase				)
												expected_callbacks.insert(0       ,  _UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												# We can also add, pop, or remove by instance
												lowerCAmelCase__        =  self.get_trainer()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[0]
												trainer.remove_callback(_UpperCamelCase				)
												expected_callbacks.remove(_UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												lowerCAmelCase__        =  self.get_trainer()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[0]
												lowerCAmelCase__        =  trainer.pop_callback(_UpperCamelCase				)
												self.assertEqual(_UpperCamelCase       ,  _UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)

												trainer.add_callback(_UpperCamelCase				)
												expected_callbacks.insert(0       ,  _UpperCamelCase				)
												self.check_callbacks_equality(trainer.callback_handler.callbacks       ,  _UpperCamelCase				)







						def  UpperCamelCase__ (		self				):






												"""simple docstring"""
												import warnings

												# XXX: for now ignore scatter_gather warnings in this test since it's not relevant to what's being tested
												warnings.simplefilter(action='ignore'       ,  category=_UpperCamelCase				)

												lowerCAmelCase__        =  self.get_trainer(callbacks=[MyTestTrainerCallback]				)
												trainer.train()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[-2].events
												self.assertEqual(_UpperCamelCase       ,  self.get_expected_events(_UpperCamelCase				)				)

												# Independent log/save/eval
												lowerCAmelCase__        =  self.get_trainer(callbacks=[MyTestTrainerCallback]       ,  logging_steps=5				)
												trainer.train()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[-2].events
												self.assertEqual(_UpperCamelCase       ,  self.get_expected_events(_UpperCamelCase				)				)

												lowerCAmelCase__        =  self.get_trainer(callbacks=[MyTestTrainerCallback]       ,  save_steps=5				)
												trainer.train()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[-2].events
												self.assertEqual(_UpperCamelCase       ,  self.get_expected_events(_UpperCamelCase				)				)

												lowerCAmelCase__        =  self.get_trainer(callbacks=[MyTestTrainerCallback]       ,  eval_steps=5       ,  evaluation_strategy='steps'				)
												trainer.train()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[-2].events
												self.assertEqual(_UpperCamelCase       ,  self.get_expected_events(_UpperCamelCase				)				)

												lowerCAmelCase__        =  self.get_trainer(callbacks=[MyTestTrainerCallback]       ,  evaluation_strategy='epoch'				)
												trainer.train()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[-2].events
												self.assertEqual(_UpperCamelCase       ,  self.get_expected_events(_UpperCamelCase				)				)

												# A bit of everything
												lowerCAmelCase__        =  self.get_trainer(
												    callbacks=[MyTestTrainerCallback]       ,  logging_steps=3       ,  save_steps=10       ,  eval_steps=5       ,  evaluation_strategy='steps'       ,  )
												trainer.train()
												lowerCAmelCase__        =  trainer.callback_handler.callbacks[-2].events
												self.assertEqual(_UpperCamelCase       ,  self.get_expected_events(_UpperCamelCase				)				)

												# warning should be emitted for duplicated callbacks
												with patch('transformers.trainer_callback.logger.warning'				) as warn_mock:
																		lowerCAmelCase__        =  self.get_trainer(
																		    callbacks=[MyTestTrainerCallback, MyTestTrainerCallback]       ,  )
																		assert str(_UpperCamelCase				) in warn_mock.call_args[0][0]













from __future__ import annotations

from collections.abc import Generator

import requests
from bsa import BeautifulSoup

__snake_case      :      Any             =       """https://www.indeed.co.in/jobs?q=mobile+app+development&l="""







def 		_UpperCamelCase				(      UpperCamelCase_    :   str = "mumbai"						)					->				Generator[tuple[str, str], None, None]:

						"""simple docstring"""



						lowerCAmelCase__        =  BeautifulSoup(requests.get(url + location						).content      ,    'html.parser'						)
						# This attribute finds out all the specifics listed in a job
						for job in soup.find_all('div'      ,    attrs={'data-tn-component': 'organicJob'}						):
												lowerCAmelCase__        =  job.find('a'      ,    attrs={'data-tn-element': 'jobTitle'}						).text.strip()
												lowerCAmelCase__        =  job.find('span'      ,    {'class': 'company'}						).text.strip()
												yield job_title, company_name


if __name__ == "__main__":
					for i, job in enumerate(fetch_jobs("""Bangalore"""), 1):
										print(f'Job {i:>2} is {job[0]} at {job[1]}')





