Best Python code snippet using pytest-play_python
test_dtaler.py
Source:test_dtaler.py
...13 dtaler.draw(True, AutoplotDisplay())14 assert isinstance(_get_parameter(display_mock), Image)15@patch("autoplot.dtaler.display")16def test_force_draw_with_variable_update(display_mock, dtaler):17 dtaler.update_variables({})18 dtaler.draw(True, AutoplotDisplay())19 assert isinstance(_get_parameter(display_mock), Image)20@patch("autoplot.dtaler.display")21def test_force_draw_with_variable_update_and_unexpected_data_id(display_mock, dtaler):22 dtaler.update_variables({})23 output = AutoplotDisplay()24 output.data_id = "1"25 dtaler.draw(True, output)26 assert isinstance(_get_parameter(display_mock), Image)27@patch("autoplot.dtaler.display")28def test_draw_dataframe(display_mock, dtaler):29 df = pd.DataFrame({"a": [1, 2, 3]})30 dtaler.update_variables({"df": df})31 dtaler.draw(False, AutoplotDisplay())32 assert all(_get_parameter(display_mock).data == df)33@patch("autoplot.dtaler.display")34def test_draw_new_dataframe(display_mock, dtaler):35 df1 = pd.DataFrame({"a": [1, 2, 3]})36 df2 = pd.DataFrame({"b": [1, 2, 3]})37 output = AutoplotDisplay()38 vars = {"df1": df1}39 dtaler.update_variables(vars)40 vars["df2"] = df241 dtaler.update_variables(vars)42 output.data_id = dtaler._tracked["df1"].dd._data_id43 dtaler.draw(False, output)44 assert all(_get_parameter(display_mock).data == df2)45 assert len(dtaler._tracked) == 246@patch("autoplot.dtaler.display")47def test_draw_reassigned_dataframe(display_mock, dtaler):48 df1 = pd.DataFrame({"a": [1, 2, 3]})49 df2 = pd.DataFrame({"a": [4, 5, 6]})50 output = AutoplotDisplay()51 vars = {"df1": df1, "df2": df2}52 dtaler.update_variables(vars)53 new_df1 = pd.DataFrame({"a": [7, 8, 9]})54 vars["df1"] = new_df155 dtaler.update_variables(vars)56 output.data_id = dtaler._tracked["df1"].dd._data_id57 dtaler.draw(False, output)58 assert all(_get_parameter(display_mock).data == df1)59 assert len(dtaler._tracked) == 260 assert dtaler._tracked["df1"].pdf is new_df161@patch("autoplot.dtaler.display")62def test_draw_does_not_reload_hidden_df(display_mock, dtaler):63 df1 = pd.DataFrame({"a": [1, 2, 3]})64 df2 = pd.DataFrame({"a": [4, 5, 6]})65 output = AutoplotDisplay()66 vars = {"df1": df1, "df2": df2}67 dtaler.update_variables(vars)68 vars["df1"] = pd.DataFrame({"a": [1, 2, 3]})69 dtaler.update_variables(vars)70 output.data_id = dtaler._tracked["df2"].dd._data_id71 dtaler.draw(False, output)72 assert not display_mock.called73 assert len(dtaler._tracked) == 274@patch("autoplot.dtaler.display")75def test_draw_external_data_id_does_not_reload(display_mock, dtaler):76 df1 = pd.DataFrame({"a": [1, 2, 3]})77 df2 = pd.DataFrame({"a": [4, 5, 6]})78 df3 = pd.DataFrame({"a": [7, 8, 9]})79 output = AutoplotDisplay()80 vars = {"df1": df1, "df2": df2}81 dtaler.update_variables(vars)82 vars["df1"] = pd.DataFrame({"a": [1, 2, 3]})83 output.data_id = dtale.show(df3, ignore_duplicate=True)._data_id84 dtaler.update_variables(vars)85 dtaler.draw(False, output)86 assert not display_mock.called87def test_do_not_reinsert_externally_removed_frames_when_variable_is_updated(dtaler):88 df1 = pd.DataFrame({"a": [1, 2, 3]})89 df2 = pd.DataFrame({"b": [1, 2, 3]})90 vars = {"df1": df1, "df2": df2}91 dtaler.update_variables(vars)92 dtale.global_state.cleanup(dtaler._tracked["df1"].dd._data_id)93 vars["df1"] = pd.DataFrame({"a": [4, 5, 6]})94 dtaler.update_variables(vars)95 assert len(dtaler._tracked) == 196 assert dtaler._ignored == {"df1"}97 assert "df1" not in dtaler._tracked98def test_do_not_reinsert_externally_removed_frames_when_variable_is_the_same(dtaler):99 df1 = pd.DataFrame({"a": [1, 2, 3]})100 df2 = pd.DataFrame({"b": [1, 2, 3]})101 vars = {"df1": df1, "df2": df2}102 dtaler.update_variables(vars)103 old_dd = dtaler._tracked["df1"].dd104 dtale.global_state.cleanup(old_dd._data_id)105 dtaler.update_variables(vars)106 assert len(dtaler._tracked) == 1107 assert dtaler._ignored == {"df1"}108 assert "df1" not in dtaler._tracked109@patch("autoplot.dtaler.display")110def test_draw_doesnt_reload_hidden_dfs(display_mock, dtaler):111 df1 = pd.DataFrame({"a": [1, 2, 3]})112 df2 = pd.DataFrame({"a": [4, 5, 6]})113 output = AutoplotDisplay()114 vars = {"df1": df1, "df2": df2}115 dtaler.update_variables(vars)116 output.data_id = dtaler._tracked["df1"].dd._data_id117 vars.pop("df2")118 dtaler.update_variables(vars)119 dtaler.draw(False, output)120 assert not display_mock.called121 assert len(dtaler._tracked) == 1122@patch("autoplot.dtaler.display")123def test_draw_reloads_when_visible_df_deleted(display_mock, dtaler):124 df1 = pd.DataFrame({"a": [1, 2, 3]})125 df2 = pd.DataFrame({"b": [1, 2, 3]})126 output = AutoplotDisplay()127 vars = {"df1": df1, "df2": df2}128 dtaler.update_variables(vars)129 output.data_id = dtaler._tracked["df2"].dd._data_id130 vars.pop("df2")131 dtaler.update_variables(vars)132 dtaler.draw(False, output)133 assert all(_get_parameter(display_mock).data == df1)134 assert len(dtaler._tracked) == 1135@patch("autoplot.dtaler.display")136def test_ignore_new_variables_when_frozen(display_mock, dtaler):137 df1 = pd.DataFrame({"a": [1, 2, 3]})138 output = AutoplotDisplay()139 dtaler.freeze(Toast(Output()))140 dtaler.update_variables({"df1": df1})141 dtaler.draw(True, output)142 assert isinstance(_get_parameter(display_mock), Image)143 assert "df1" not in dtaler._tracked144 assert "df1" in dtaler._ignored145@patch("autoplot.dtaler.display")146def test_update_non_ignored_variables(display_mock, dtaler):147 df1 = pd.DataFrame({"a": [1, 2, 3]})148 output = AutoplotDisplay()149 dtaler.update_variables({"df1": df1})150 dtaler.freeze(Toast(Output()))151 new_df1 = pd.DataFrame({"b": [4, 5, 6]})152 dtaler.update_variables({"df1": new_df1})153 dtaler.draw(True, output)154 assert all(_get_parameter(display_mock).data == new_df1)155 assert dtaler._tracked["df1"].pdf is new_df1156 assert "df1" not in dtaler._ignored157def test_update_ignored_variables_still_ignored(dtaler):158 df1 = pd.DataFrame({"a": [1, 2, 3]})159 dtaler.freeze(Toast(Output()))160 dtaler.update_variables({"df1": df1})161 new_df1 = pd.DataFrame({"b": [4, 5, 6]})162 dtaler.update_variables({"df1": new_df1})163 assert "df1" not in dtaler._tracked164 assert "df1" in dtaler._ignored165def test_remove_ignored_variables(dtaler):166 df1 = pd.DataFrame({"a": [1, 2, 3]})167 dtaler.freeze(Toast(Output()))168 dtaler.update_variables({"df1": df1})169 dtaler.update_variables({})170 assert len(dtaler._tracked) == 0171 assert len(dtaler._ignored) == 0172@patch("autoplot.dtaler.display")173def test_continue_to_ignore_after_defrost(display_mock, dtaler):174 df1 = pd.DataFrame({"a": [1, 2, 3]})175 output = AutoplotDisplay()176 dtaler.freeze(Toast(Output()))177 dtaler.update_variables({"df1": df1})178 dtaler.defrost(Toast(Output()))179 dtaler.update_variables({"df1": df1})180 dtaler.draw(True, output)181 assert isinstance(_get_parameter(display_mock), Image)182 assert "df1" not in dtaler._tracked183 assert "df1" in dtaler._ignored184@patch("autoplot.dtaler.display")185def test_accept_new_variables_after_defrost(display_mock, dtaler):186 df1 = pd.DataFrame({"a": [1, 2, 3]})187 df2 = pd.DataFrame({"b": [4, 5, 6]})188 output = AutoplotDisplay()189 dtaler.freeze(Toast(Output()))190 dtaler.update_variables({"df1": df1})191 dtaler.defrost(Toast(Output()))192 dtaler.update_variables({"df1": df1, "df2": df2})193 dtaler.draw(False, output)194 assert all(_get_parameter(display_mock).data == df2)195 assert "df1" not in dtaler._tracked196 assert "df2" in dtaler._tracked197 assert "df1" in dtaler._ignored198 assert "df2" not in dtaler._ignored199@patch("autoplot.dtaler.display")200def test_ignore_current_variable_no_fallback(display_mock, dtaler):201 df1 = pd.DataFrame({"a": [1, 2, 3]})202 output = AutoplotDisplay()203 dtaler.update_variables({"df1": df1})204 output.data_id = dtaler._tracked["df1"].dd._data_id205 dtaler.ignore_variable(Toast(Output()), "df1")206 dtaler.update_variables({"df1": df1})207 dtaler.draw(False, output)208 assert isinstance(_get_parameter(display_mock), Image)209 assert "df1" not in dtaler._tracked210 assert "df1" in dtaler._ignored211@patch("autoplot.dtaler.display")212def test_ignore_current_variable_with_fallback(display_mock, dtaler):213 df1 = pd.DataFrame({"a": [1, 2, 3]})214 df2 = pd.DataFrame({"a": [4, 5, 6]})215 output = AutoplotDisplay()216 dtaler.update_variables({"df1": df1, "df2": df2})217 output.data_id = dtaler._tracked["df1"].dd._data_id218 dtaler.ignore_variable(Toast(Output()), "df1")219 dtaler.update_variables({"df1": df1, "df2": df2})220 dtaler.draw(False, output)221 assert all(_get_parameter(display_mock).data == df2)222 assert "df1" not in dtaler._tracked223 assert "df1" in dtaler._ignored224@patch("autoplot.dtaler.display")225def test_ignore_other_variable_with_fallback(display_mock, dtaler):226 df1 = pd.DataFrame({"a": [1, 2, 3]})227 df2 = pd.DataFrame({"a": [4, 5, 6]})228 output = AutoplotDisplay()229 dtaler.update_variables({"df1": df1, "df2": df2})230 output.data_id = dtaler._tracked["df1"].dd._data_id231 dtaler.ignore_variable(Toast(Output()), "df2")232 dtaler.update_variables({"df1": df1, "df2": df2})233 dtaler.draw(False, output)234 assert not display_mock.called235 assert "df2" not in dtaler._tracked236 assert "df2" in dtaler._ignored237@patch("autoplot.dtaler.display")238def test_show_ignored_variable(display_mock, dtaler):239 df1 = pd.DataFrame({"a": [1, 2, 3]})240 df2 = pd.DataFrame({"a": [4, 5, 6]})241 output = AutoplotDisplay()242 dtaler.update_variables({"df1": df1, "df2": df2})243 output.data_id = dtaler._tracked["df1"].dd._data_id244 dtaler.ignore_variable(Toast(Output()), "df2")245 dtaler.update_variables({"df1": df1, "df2": df2})246 dtaler.show_variable(Toast(Output()), "df2")247 dtaler.update_variables({"df1": df1, "df2": df2})248 dtaler.draw(False, output)249 assert all(_get_parameter(display_mock).data == df2)250 assert "df2" in dtaler._tracked251 assert "df2" not in dtaler._ignored252@patch("autoplot.dtaler.display")253def test_show_variable(display_mock, dtaler):254 df1 = pd.DataFrame({"a": [1, 2, 3]})255 df2 = pd.DataFrame({"a": [4, 5, 6]})256 output = AutoplotDisplay()257 dtaler.update_variables({"df1": df1, "df2": df2})258 output.data_id = dtaler._tracked["df2"].dd._data_id259 dtaler.show_variable(Toast(Output()), "df1")260 dtaler.update_variables({"df1": df1, "df2": df2})261 dtaler.draw(False, output)262 assert all(_get_parameter(display_mock).data == df1)263 assert "df2" in dtaler._tracked264 assert "df2" not in dtaler._ignored265@patch("autoplot.dtaler.display")266def test_show_frozen_variable(display_mock, dtaler):267 df1 = pd.DataFrame({"a": [1, 2, 3]})268 df2 = pd.DataFrame({"a": [4, 5, 6]})269 output = AutoplotDisplay()270 dtaler.update_variables({"df1": df1})271 output.data_id = dtaler._tracked["df1"].dd._data_id272 dtaler.freeze(Toast(Output()))273 dtaler.update_variables({"df1": df1, "df2": df2})274 assert "df2" not in dtaler._tracked275 assert "df2" in dtaler._ignored276 dtaler.show_variable(Toast(Output()), "df2")277 dtaler.update_variables({"df1": df1, "df2": df2})278 dtaler.draw(False, output)279 assert all(_get_parameter(display_mock).data == df2)280 assert "df2" in dtaler._tracked281 assert "df2" not in dtaler._ignored282@patch("autoplot.dtaler.display")283def test_delete_from_dtale_and_namespace(display_mock, dtaler):284 df1 = pd.DataFrame({"a": [1, 2, 3]})285 df2 = pd.DataFrame({"a": [4, 5, 6]})286 output = AutoplotDisplay()287 dtaler.update_variables({"df1": df1, "df2": df2})288 output.data_id = dtaler._tracked["df1"].dd._data_id289 dtale.global_state.cleanup(dtaler._tracked["df1"].dd._data_id)290 dtaler.update_variables({"df2": df2})291 dtaler.draw(False, output)292 assert all(_get_parameter(display_mock).data == df2)293 assert "df1" not in dtaler._tracked294 assert "df1" not in dtaler._ignored295def _get_parameter(display_mock) -> Union[Image, VarData]:296 return display_mock.call_args[0][0]297@pytest.fixture298def dtaler():299 dtaler = DTaler()300 yield dtaler...
test_update.py
Source:test_update.py
1from datetime import timedelta2from django.utils import timezone3from jnt_django_graphene_toolbox.errors import GraphQLPermissionDenied4from apps.core.gitlab import GITLAB_DATE_FORMAT5from apps.development.models import TeamMember6from apps.payroll.models.work_break import WorkBreak, WorkBreakReason7from apps.users.models import User8from tests.test_development.factories import TeamFactory, TeamMemberFactory9from tests.test_payroll.factories import WorkBreakFactory10from tests.test_users.factories import UserFactory11COMMENT_CREATED = "created"12COMMENT_UPDATED = "updated"13KEY_ID = "id"14KEY_USER = "user"15KEY_REASON = "reason"16KEY_COMMENT = "comment"17KEY_FROM_DATE = "from_date"18KEY_TO_DATE = "to_date"19def test_query(user, gql_client, gql_raw):20 """Test update raw query."""21 gql_client.set_user(user)22 team = TeamFactory.create()23 TeamMemberFactory.create(24 team=team,25 user=user,26 roles=TeamMember.roles.LEADER,27 )28 user.roles = User.roles.TEAM_LEADER29 user.save()30 work_break = WorkBreakFactory.create(user=user, comment=COMMENT_CREATED)31 update_variables = {32 KEY_ID: work_break.pk,33 KEY_USER: user.id,34 "fromDate": _date_strftime(timezone.now()),35 "toDate": _date_strftime(timezone.now() + timedelta(minutes=10)),36 KEY_REASON: WorkBreakReason.DAYOFF,37 KEY_COMMENT: "test comment",38 }39 response = gql_client.execute(40 gql_raw("update_work_break"),41 variable_values=update_variables,42 )43 dto = response["data"]["updateWorkBreak"]["workBreak"]44 assert dto[KEY_ID] == str(work_break.pk)45 assert dto[KEY_USER][KEY_ID] == str(update_variables[KEY_USER])46 assert dto[KEY_COMMENT] == update_variables[KEY_COMMENT]47def test_work_break_not_team_lead(48 ghl_auth_mock_info,49 update_work_break_mutation,50):51 """52 Test work break not team lead.53 :param ghl_auth_mock_info:54 :param update_work_break_mutation:55 """56 work_break = WorkBreakFactory.create(comment="django")57 update_variables = {58 KEY_ID: work_break.pk,59 KEY_USER: ghl_auth_mock_info.context.user.id,60 KEY_FROM_DATE: _date_strftime(timezone.now()),61 KEY_TO_DATE: _date_strftime(timezone.now() + timedelta(minutes=10)),62 KEY_REASON: WorkBreakReason.DAYOFF,63 KEY_COMMENT: "test comment",64 }65 response = update_work_break_mutation(66 root=None,67 info=ghl_auth_mock_info,68 **update_variables,69 )70 assert isinstance(response, GraphQLPermissionDenied)71 work_break.refresh_from_db()72 assert work_break.comment == "django"73def test_update_work_break_another_user(74 ghl_auth_mock_info,75 update_work_break_mutation,76):77 """78 Test update work break another user.79 :param ghl_auth_mock_info:80 :param update_work_break_mutation:81 """82 team = TeamFactory.create()83 TeamMemberFactory.create(84 team=team,85 user=ghl_auth_mock_info.context.user,86 roles=TeamMember.roles.DEVELOPER,87 )88 user2 = UserFactory.create()89 TeamMemberFactory.create(90 team=team,91 user=user2,92 roles=TeamMember.roles.DEVELOPER,93 )94 work_break = WorkBreakFactory.create(user=user2, comment=COMMENT_CREATED)95 update_variables = {96 KEY_ID: work_break.pk,97 KEY_USER: ghl_auth_mock_info.context.user.id,98 KEY_FROM_DATE: _date_strftime(timezone.now()),99 KEY_TO_DATE: _date_strftime(timezone.now() + timedelta(minutes=10)),100 KEY_REASON: WorkBreakReason.DAYOFF,101 KEY_COMMENT: "test comment",102 }103 response = update_work_break_mutation(104 root=None,105 info=ghl_auth_mock_info,106 **update_variables,107 )108 assert isinstance(response, GraphQLPermissionDenied)109def test_update_another_user_but_team_lead(110 ghl_auth_mock_info,111 update_work_break_mutation,112 team,113 make_team_developer,114 make_team_leader,115):116 """117 Test update another user but team lead.118 :param ghl_auth_mock_info:119 :param update_work_break_mutation:120 :param team:121 :param make_team_developer:122 :param make_team_leader:123 """124 another_user = UserFactory.create()125 make_team_leader(team, ghl_auth_mock_info.context.user)126 make_team_developer(team, another_user)127 work_break = WorkBreakFactory.create(128 user=another_user,129 comment=COMMENT_CREATED,130 )131 update_variables = {132 KEY_ID: work_break.pk,133 KEY_USER: another_user.pk,134 KEY_FROM_DATE: timezone.now().date(),135 KEY_TO_DATE: timezone.now().date(),136 KEY_REASON: WorkBreakReason.DAYOFF,137 KEY_COMMENT: COMMENT_UPDATED,138 }139 update_work_break_mutation(140 root=None,141 info=ghl_auth_mock_info,142 **update_variables,143 )144 work_break.refresh_from_db()145 assert WorkBreak.objects.count() == 1146 assert work_break.comment == COMMENT_UPDATED147 assert work_break.user == another_user148def test_change_work_break_user(149 ghl_auth_mock_info,150 update_work_break_mutation,151):152 """153 Test change work break user.154 :param ghl_auth_mock_info:155 :param update_work_break_mutation:156 """157 team = TeamFactory.create()158 user2 = UserFactory.create()159 user3 = UserFactory.create()160 TeamMemberFactory.create(161 team=team,162 user=ghl_auth_mock_info.context.user,163 roles=TeamMember.roles.LEADER,164 )165 TeamMemberFactory.create(166 team=team,167 user=user2,168 roles=TeamMember.roles.DEVELOPER,169 )170 work_break = WorkBreakFactory.create(user=user2, comment=COMMENT_CREATED)171 update_variables = {172 KEY_ID: work_break.pk,173 KEY_USER: user3.id,174 KEY_FROM_DATE: timezone.now().date(),175 KEY_TO_DATE: timezone.now().date(),176 KEY_REASON: WorkBreakReason.DAYOFF,177 KEY_COMMENT: COMMENT_UPDATED,178 "paid_days": 7,179 }180 update_work_break_mutation(181 root=None,182 info=ghl_auth_mock_info,183 **update_variables,184 )185 work_break.refresh_from_db()186 assert WorkBreak.objects.count() == 1187 assert work_break.comment == COMMENT_UPDATED188 assert work_break.user == user3189 assert work_break.paid_days == update_variables["paid_days"]190def _date_strftime(date):191 """192 Date strftime.193 :param date:194 """...
board_task.py
Source:board_task.py
...49 @variables.setter50 def variables(self, value):51 self._variables = value52 @property53 def update_variables(self):54 """55 Get and set a flag that indicates if the variables should be updated56 at the end of the session57 :rtype: bool58 """59 return self._update_variables60 @update_variables.setter61 def update_variables(self, value):62 self._update_variables = value63 ##########################################################################64 ####### FUNCTIONS ########################################################65 ##########################################################################66 def create_variable(self, name=None, value=None, datatype='string'):67 """68 Create a variable69 :rtype: TaskVariable70 """71 return TaskVariable(self, name, value, datatype)72 def collect_data(self, data):73 data.update({'variables': [var.collect_data({}) for var in self.variables]})74 return data75 def save(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!