Best Python code snippet using localstack_python
hrnet.py
Source:hrnet.py  
...134        # self.bn2 = tf.keras.layers.BatchNormalization(momentum=0.1, epsilon=1e-5)135        # self.layer1 = make_bottleneck_layer(filter_num=64, blocks=4)136        # self.transition1 = self.__make_transition_layer(previous_branches_num=1,137        #                                                 previous_channels=[256],138        #                                                 current_branches_num=self.config_params.get_stage("s2")[1],139        #                                                 current_channels=self.config_params.get_stage("s2")[0])140        # self.stage2 = self.__make_stages("s2", self.config_params.get_stage("s2")[0])141        # self.transition2 = self.__make_transition_layer(previous_branches_num=self.config_params.get_stage("s2")[1],142        #                                                 previous_channels=self.config_params.get_stage("s2")[0],143        #                                                 current_branches_num=self.config_params.get_stage("s3")[1],144        #                                                 current_channels=self.config_params.get_stage("s3")[0])145        # self.stage3 = self.__make_stages("s3", self.config_params.get_stage("s3")[0])146        # self.transition3 = self.__make_transition_layer(previous_branches_num=self.config_params.get_stage("s3")[1],147        #                                                 previous_channels=self.config_params.get_stage("s3")[0],148        #                                                 current_branches_num=self.config_params.get_stage("s4")[1],149        #                                                 current_channels=self.config_params.get_stage("s4")[0])150        # self.stage4 = self.__make_stages("s4", self.config_params.get_stage("s4")[0], False)151        # self.conv3 = tf.keras.layers.Conv2D(filters=self.config_params.num_of_joints,152        #                                     kernel_size=self.config_params.conv3_kernel,153        #                                     strides=1,154        #                                     padding="same")155    # def __choose_config(self, config_name):156    #     return get_config_params(config_name)157    def __make_stages(self, inputs, stage_name, in_channels, multi_scale_output=True):158        stage_info = self.config_params.get_stage(stage_name)159        channels, num_branches, num_modules, block, num_blocks, fusion_method = stage_info160        fusion = []161        for i in range(num_modules):162            if not multi_scale_output and i == num_modules - 1:163                reset_multi_scale_output = False164            else:165                reset_multi_scale_output = True166            module_list = HighResolutionModule(num_branches=num_branches,167                                               num_in_channels=in_channels,168                                               num_channels=channels,169                                               block=block,170                                               num_blocks=num_blocks,171                                               fusion_method=fusion_method,172                                               multi_scale_output=reset_multi_scale_output)173            fusion = module_list.call(inputs)174        return fusion175    @staticmethod176    def __make_transition_layer(x, previous_branches_num, previous_channels, current_branches_num, current_channels):177        transition_layers = []178        for i in range(current_branches_num):179            if i < previous_branches_num:180                if current_channels[i] != previous_channels[i]:181                    temp = _conv2d_layer(name="trans1"+str(i), input=x, filters=current_channels[i], kernel_size=3,182                                         strides=1, padding="SAME", use_bias=False)183                    temp = _batch_norm(inputs=temp, momentum=0.1, epsilon=1e-5)184                    transition_layers.append(temp)185                    # transition_layers.append(186                    #     tf.keras.Sequential([187                    #         tf.keras.layers.Conv2D(filters=current_channels[i], kernel_size=(3, 3), strides=1, padding="same", use_bias=False),188                    #         tf.keras.layers.BatchNormalization(momentum=0.1, epsilon=1e-5),189                    #         tf.keras.layers.ReLU()190                    #     ])191                    # )192                else:193                    transition_layers.append(x)194            else:195                down_sampling_layers = []196                for j in range(i + 1 - previous_branches_num):197                    in_channels = previous_channels[-1],198                    out_channels = current_channels[i] if j == i - previous_branches_num else in_channels199                    with flow.scope.namespace('transition_layers_'+str(j)):200                        temp = _conv2d_layer(name="fuse11", input=x, filters=out_channels,201                                             kernel_size=3, strides=2, padding="SAME", use_bias=False)202                        temp = _batch_norm(inputs=temp, momentum=0.1, epsilon=1e-5)203                        temp = flow.nn.relu(temp)204                        down_sampling_layers.append(temp)205                        # down_sampling_layers.append(206                        #     tf.keras.Sequential([207                        #         tf.keras.layers.Conv2D(filters=out_channels, kernel_size=(3, 3), strides=2,208                        #                                padding="same", use_bias=False),209                        #         tf.keras.layers.BatchNormalization(momentum=0.1, epsilon=1e-5),210                        #         tf.keras.layers.ReLU()211                        #     ])212                        # )213                transition_layers.append(down_sampling_layers)214        return transition_layers215    def call(self, inputs, training=None):#mask=None216        x = _conv2d_layer(name="conv1", input=inputs, filters=64,217                          kernel_size=3, strides=2, padding="SAME", use_bias=False)218        # x = self.conv1(inputs)219        x = _batch_norm(inputs=x, momentum=0.1, epsilon=1e-5)220        # x = self.bn1(x, training=training)221        x = flow.nn.relu(x)222        # x = tf.nn.relu(x)223        x = _conv2d_layer(name="conv2", input=x, filters=64,224                          kernel_size=3, strides=2, padding="SAME", use_bias=False)225        # x = self.conv2(x)226        x = _batch_norm(inputs=x, momentum=0.1, epsilon=1e-5)227        # x = self.bn2(x, training=training)228        x = flow.nn.relu(x)229        # x = tf.nn.relu(x)230        x = make_bottleneck_layer(x, training=training, filter_num=64, blocks=4)231        # x = self.layer1(x, training=training)232        feature_list = []233        for i in range(self.config_params.get_stage("s2")[1]):234            result = self.__make_transition_layer(x=x,235                                                  previous_branches_num=1,236                                                  previous_channels=[256],237                                                  current_branches_num=self.config_params.get_stage("s2")[1],238                                                  current_channels=self.config_params.get_stage("s2")[0])239            if result[i] is not None:240                feature_list.append(result[i])241            # if self.transition1[i] is not None:242            #     feature_list.append(self.transition1[i](x, training=training))243            else:244                feature_list.append(x)245        y_list = self.__make_stages(feature_list, "s2", self.config_params.get_stage("s2")[0])246        # y_list = self.stage2(feature_list, training=training)247        feature_list = []248        for i in range(self.config_params.get_stage("s3")[1]):249            result = self.__make_transition_layer(x=y_list[-1],250                                                  previous_branches_num=self.config_params.get_stage("s2")[1],251                                                  previous_channels=self.config_params.get_stage("s2")[0],252                                                  current_branches_num=self.config_params.get_stage("s3")[1],253                                                  current_channels=self.config_params.get_stage("s3")[0])254            if result[i] is not None:255                feature_list.append(result[i])256            # if self.transition2[i] is not None:257            #     feature_list.append(self.transition2[i](y_list[-1], training=training))258            else:259                feature_list.append(y_list[i])260        y_list = self.__make_stages(feature_list, "s3", self.config_params.get_stage("s3")[0])261        # y_list = self.stage3(feature_list, training=training)262        feature_list = []263        for i in range(self.config_params.get_stage("s4")[1]):264            result = self.__make_transition_layer(x=y_list[-1],265                                                  previous_branches_num=self.config_params.get_stage("s3")[1],266                                                  previous_channels=self.config_params.get_stage("s3")[0],267                                                  current_branches_num=self.config_params.get_stage("s4")[1],268                                                  current_channels=self.config_params.get_stage("s4")[0])269            if result[i] is not None:270                feature_list.append(result[i])271        # for i in range(self.config_params.get_stage("s4")[1]):272        #     if self.transition3[i] is not None:273        #         feature_list.append(self.transition3[i](y_list[-1], training=training))274            else:275                feature_list.append(y_list[i])276        y_list = self.__make_stages(feature_list, "s4", self.config_params.get_stage("s4")[0], False)277        # y_list = self.stage4(feature_list, training=training)278        outputs = _conv2d_layer(name="conv3",279                                input=y_list[0],280                                filters=self.config_params.num_of_joints,281                                kernel_size=self.config_params.conv3_kernel,282                                strides=1,283                                padding="SAME")284        # outputs = self.conv3(y_list[0])...test_dungeon.py
Source:test_dungeon.py  
...21    d = dungeon.Dungeon(hero)22    d.mk_next_stage.assert_called_once()23def test_dungeon_init__hero_exists_on_stage(hero):24    d = dungeon.Dungeon(hero)25    m = d.get_stage()26    assert any([True for e in m.entities if e.has_comp('human')])27def test_dungeon_init__move_hero_called(mocker, hero):28    mocker.patch.object(dungeon.Dungeon, 'move_hero')29    d = dungeon.Dungeon(hero)30    d.move_hero.assert_called_once()31def test_dungeon_init__populate_called(mocker, hero):32    mocker.patch.object(stages.Stage, 'populate')33    d = dungeon.Dungeon(hero)34    m = d.get_stage()35    m.populate.assert_called_once()36def test_get_stage__1_level(hero):37    d = dungeon.Dungeon(hero)38    m = d.get_stage()39    assert m.dungeon_lvl == d.current_stage + 140def test_get_stage__2_stages(hero):41    d = dungeon.Dungeon(hero)42    d.mk_next_stage()43    m = d.get_stage()44    assert m.dungeon_lvl == d.current_stage + 145    d.current_stage = 146    m = d.get_stage()47    assert m.dungeon_lvl == d.current_stage + 148# def test_place_hero(, level):49    # Should this take the hero as a parameter?50    # Test that the hero is put somewhere51def test_mk_next_stage__stages_increases(hero):52    d = dungeon.Dungeon(hero)53    assert len(d.stages) == 154    d.mk_next_stage()55    assert len(d.stages) == 256def test_mk_next_stage__stages_are_numbered_correctly(hero):57    d = dungeon.Dungeon(hero)58    assert d.stages[0].dungeon_lvl == 159    d.mk_next_stage()60    assert d.stages[1].dungeon_lvl == 261def test_hero_at_stairs__valid_returns_True(hero):62    d = dungeon.Dungeon(hero)63    down_stair = d.get_stage().find_stair('>')64    d.hero.x, d.hero.y = down_stair.x, down_stair.y65    assert d.hero_at_stairs('>')66def test_hero_at_stairs__invalid_returns_False(hero):67    d = dungeon.Dungeon(hero)68    assert d.hero_at_stairs('>') is False69def test_hero_at_stairs__starting_upstair_returns_True(hero):70    d = dungeon.Dungeon(hero)71    # Hero starts on an upstair, so this should be True.72    assert d.hero_at_stairs('<')73def test_move_downstairs__not_on_down_stair_returns_False(hero):74    d = dungeon.Dungeon(hero)75    d.mk_next_stage()76    result = d.move_downstairs()77    assert result is False78def test_move_downstairs__hero_moved_to_next_upstair(hero):79    d = dungeon.Dungeon(hero)80    down_stair = d.get_stage().find_stair('>')81    d.hero.x, d.hero.y = down_stair.x, down_stair.y82    d.mk_next_stage()83    d.move_downstairs()84    up_stair = d.get_stage().find_stair('<')85    assert d.hero.x == up_stair.x86    assert d.hero.y == up_stair.y87def test_move_downstairs__dungeon_lvl_incremented(hero):88    d = dungeon.Dungeon(hero)89    prev_lvl = d.current_stage90    down_stair = d.get_stage().find_stair('>')91    d.hero.x, d.hero.y = down_stair.x, down_stair.y92    d.mk_next_stage()93    d.move_downstairs()94    assert d.current_stage == prev_lvl + 195def test_move_downstairs__success_returns_True(hero):96    d = dungeon.Dungeon(hero)97    down_stair = d.get_stage().find_stair('>')98    d.hero.x, d.hero.y = down_stair.x, down_stair.y99    d.mk_next_stage()100    assert d.move_downstairs()101def test_move_upstairs__not_on_up_stair_returns_False(hero):102    d = dungeon.Dungeon(hero)103    down_stair = d.get_stage().find_stair('>')104    # Move hero to downstair (won't be on upstair)105    d.hero.x, d.hero.y = down_stair.x, down_stair.y106    assert d.move_upstairs() is False107def test_move_upstairs__hero_moved_to_prev_downstair(hero):108    d = dungeon.Dungeon(hero)109    down_stair = d.get_stage().find_stair('>')110    d.hero.x, d.hero.y = down_stair.x, down_stair.y111    d.mk_next_stage()112    # Move the hero downstairs first113    d.move_downstairs()114    # Hero moves back to previous down-stair115    d.move_upstairs()116    assert d.hero.x == down_stair.x117    assert d.hero.y == down_stair.y118def test_move_upstairs__success_returns_True(hero):119    d = dungeon.Dungeon(hero)120    down_stair = d.get_stage().find_stair('>')121    d.hero.x, d.hero.y = down_stair.x, down_stair.y122    d.mk_next_stage()123    d.move_downstairs()124    assert d.move_upstairs()125# def test_move_upstairs__when_at_the_top_lvl():126    # Return False?127# Wait on this test - might want to remove some calls from Dungeon init128# def test_move_hero__hero_not_placed_yet(hero):129    # d = dungeon.Dungeon(hero)130def test_move_hero__to_wall_returns_False(hero):131    d = dungeon.Dungeon(hero)132    m = stages.Stage(10, 10, 2)133    d.stages.append(m)134    assert d.move_hero(dest_stage_index=1, dest_x=0, dest_y=0) is False135def test_move_hero__to_occupied_spot_returns_False(hero):136    d = dungeon.Dungeon(hero)137    rnd_monster = [e for e in d.get_stage().entities if e.has_comp('ai')].pop()138    dest_x = rnd_monster.x139    dest_y = rnd_monster.y140    assert d.move_hero(dest_stage_index=0, dest_x=dest_x, dest_y=dest_y) is False141def test_move_hero__same_floor_returns_True(hero):142    d = dungeon.Dungeon(hero)143    dest_x, dest_y = d.get_stage().get_random_open_spot()144    assert d.move_hero(dest_stage_index=0, dest_x=dest_x, dest_y=dest_y)145def test_move_hero__same_floor_hero_xy_updated(hero):146    d = dungeon.Dungeon(hero)147    dest_x, dest_y = d.get_stage().get_random_open_spot()148    d.move_hero(dest_stage_index=0, dest_x=dest_x, dest_y=dest_y)149    assert d.hero.x == dest_x150    assert d.hero.y == dest_y151def test_move_hero__same_floor_lvl_remains_same(hero):152    d = dungeon.Dungeon(hero)153    d_lvl = d.current_stage154    dest_x, dest_y = d.get_stage().get_random_open_spot()155    d.move_hero(dest_stage_index=0, dest_x=dest_x, dest_y=dest_y)156    assert d.current_stage == d_lvl157def test_move_hero__diff_floor_returns_True(hero):158    dest_stage_index = 1159    d = dungeon.Dungeon(hero)160    d.mk_next_stage()161    dest_x, dest_y = d.stages[dest_stage_index].get_random_open_spot()162    assert d.move_hero(dest_stage_index=dest_stage_index, dest_x=dest_x, dest_y=dest_y)163def test_move_hero__diff_floor_hero_xy_updated(hero):164    dest_stage_index = 1165    d = dungeon.Dungeon(hero)166    d.mk_next_stage()167    dest_x, dest_y = d.stages[dest_stage_index].get_random_open_spot()168    d.move_hero(dest_stage_index=dest_stage_index, dest_x=dest_x, dest_y=dest_y)...models.py
Source:models.py  
...8POSTTEST    = "posttest"9class PolicyworldWork(object):10    def __init__(self, stages):11        self.stages = stages12    def get_stage(self, name):13        for s in self.stages:14            if s.name == name:15                return s16        return None17    18    def get_time(self):19        t = 020        for s in self.stages:21            t = t + s.get_minutes()22        return t23    24    def to_grade(self):25        #return "%s %s %s %s %s %s time:%s" % (self._passed_to_string(self.get_stage(PRETEST).passed),26        #                                      self._passed_to_string(self.get_stage(PROBLEM_1).passed),27        #                                      self._passed_to_string(self.get_stage(PROBLEM_2).passed),28        #                                      self._passed_to_string(self.get_stage(PROBLEM_3).passed),29        #                                      self._passed_to_string(self.get_stage(DEBATETEST).passed),30        #                                      self._passed_to_string(self.get_stage(POSTTEST).passed),31        #                                      self.get_time())32        return "Pre:%s Post1:%s Post2:%s Time:%s" % (self._grade_stage(PRETEST),33                                                    self._grade_stage(DEBATETEST),34                                                    self._grade_stage(POSTTEST),35                                                    self.get_time())36    def _grade_stage(self, stage_name):37        s = self.get_stage(stage_name)38        if s == None:39            return "?"40        41        if s.passed:42            return '+'43        else:44            return '-'45    46class StageGrade(object):47    def __init__(self, name, attempt, completed, passed, msec):48        self.name       = name49        self.attempt    = attempt50        self.completed  = completed51        self.passed     = passed...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!!
