Best Python code snippet using toolium_python
test_fictplay.py
Source:test_fictplay.py  
...16        # symmetric 2x2 coordination game17        payoff_matrix = [[4, 0],18                         [3, 2]]19        self.fp = FictitiousPlay(payoff_matrix)20    def test_set_init_actions_with_given_init_actions(self):21        init_actions = (0, 1)22        self.fp.set_init_actions(init_actions)23        assert_array_equal(self.fp.current_actions, init_actions)24        for i, current_belief in enumerate(self.fp.current_beliefs):25            ok_(current_belief[init_actions[1-i]] == 1 and26                current_belief.sum() == 1)27    def test_set_init_actions_when_init_action_dist_None(self):28        self.fp.set_init_actions()  # Action dist randomly chosen29        init_actions = self.fp.current_actions30        for i, current_belief in enumerate(self.fp.current_beliefs):31            ok_(current_belief[init_actions[1-i]] == 1 and32                current_belief.sum() == 1)33    def test_play(self):34        init_actions = (0, 1)35        best_responses = (1, 0)36        self.fp.set_init_actions(init_actions)37        self.fp.play()38        assert_array_equal(self.fp.current_actions, best_responses)39    def test_simulate_rest_point(self):40        beliefs_sequence = \41            self.fp.simulate(ts_length=3, init_actions=(0, 0))42        assert_array_equal(43            beliefs_sequence[0],44            [[1, 0],45             [1, 0],46             [1, 0]]47            )48    def test_simulate(self):49        beliefs_sequence = \50            self.fp.simulate(ts_length=3, init_actions=(0, 1))51        # played actions: (0, 1), (1, 0), (0, 1)52        assert_array_almost_equal_nulp(53            beliefs_sequence[0],54            [[0, 1],55             [1/2, 1/2],56             [1/3, 2/3]]57            )58class TestFictitiousPlay_bimatrix:59    '''Test the methods of FictitiousPlay with bimatrix'''60    def setUp(self):61        '''Setup a FictitiousPlay instance'''62        payoff_bimatrix = np.zeros((2, 3, 2))  # 2 x 3 game63        g = NormalFormGame(payoff_bimatrix)64        self.fp = FictitiousPlay(g)65    def test_set_init_actions_with_given_init_actions(self):66        init_actions = (0, 2)67        self.fp.set_init_actions(init_actions)68        assert_array_equal(self.fp.current_actions, init_actions)69        for i, current_belief in enumerate(self.fp.current_beliefs):70            ok_(current_belief[init_actions[1-i]] == 1 and71                current_belief.sum() == 1)72    def test_set_init_actions_when_init_action_dist_None(self):73        self.fp.set_init_actions()  # Action dist randomly chosen74        init_actions = self.fp.current_actions75        for i, current_belief in enumerate(self.fp.current_beliefs):76            ok_(current_belief[init_actions[1-i]] == 1 and77                current_belief.sum() == 1)78# Invalid inputs #79@raises(ValueError)80def test_fp_invalid_input():81    fp = FictitiousPlay(np.zeros((2, 3, 4, 3)))  # three-player game82if __name__ == '__main__':83    import sys84    import nose85    argv = sys.argv[:]86    argv.append('--verbose')87    argv.append('--nocapture')...logitdyn.py
Source:logitdyn.py  
...36            # cdfs left unnormalized37            player.logit_choice_cdfs = \38                np.exp(payoff_array_rotated*self.beta).cumsum(axis=-1)39            # player.logit_choice_cdfs /= player.logit_choice_cdfs[..., [-1]]40    def set_init_actions(self, init_actions=None):41        if init_actions is None:42            init_actions = np.empty(self.N, dtype=int)43            for i in range(self.N):44                init_actions[i] = np.random.randint(self.nums_actions[i])45        self.current_actions[:] = init_actions46    def play(self, player_ind):47        i = player_ind48        # Tuple of the actions of opponent players i+1, ..., N, 0, ..., i-149        opponent_actions = \50            tuple(self.current_actions[i+1:]) + tuple(self.current_actions[:i])51        cdf = self.players[i].logit_choice_cdfs[opponent_actions]52        random_value = np.random.random()53        next_action = cdf.searchsorted(random_value*cdf[-1], side='right')54        self.current_actions[i] = next_action55    def simulate(self, ts_length, init_actions=None):56        """57        Return array of ts_length arrays of N actions58        """59        actions_sequence = np.empty((ts_length, self.N), dtype=int)60        actions_sequence_iter = \61            self.simulate_iter(ts_length, init_actions=init_actions)62        for t, actions in enumerate(actions_sequence_iter):63            actions_sequence[t] = actions64        return actions_sequence65    def simulate_iter(self, ts_length, init_actions=None):66        """67        Iterator version of `simulate`68        """69        self.set_init_actions(init_actions=init_actions)70        player_ind_sequence = np.random.randint(self.N, size=ts_length)71        for t in range(ts_length):72            yield self.current_actions73            self.play(player_ind=player_ind_sequence[t])74    def replicate(self, T, num_reps, init_actions=None):75        out = np.empty((num_reps, self.N), dtype=int)76        for j in range(num_reps):77            actions_sequence_iter = \78                self.simulate_iter(T+1, init_actions=init_actions)79            for actions in actions_sequence_iter:80                x = actions81            out[j] = x...test_hbase.py
Source:test_hbase.py  
1import pkg_resources2from absl.testing import absltest3from absl.testing import parameterized4from integration_tests.dataproc_test_case import DataprocTestCase5class HBaseTestCase(DataprocTestCase):6    COMPONENT = 'hbase'7    INIT_ACTIONS = ['hbase/hbase.sh']8    INIT_ACTIONS_FOR_NOT_HA = ['zookeeper/zookeeper.sh']9    GCS_BUCKET = None10    def setUp(self):11        super().setUp()12        self.GCS_BUCKET = "test-hbase-{}-{}".format(self.datetime_str(),13                                                    self.random_str())14        self.assert_command('gsutil mb -c regional -l {} gs://{}'.format(15            self.REGION, self.GCS_BUCKET))16    def tearDown(self):17        self.assert_command('gsutil -m rm -rf gs://{}'.format(self.GCS_BUCKET))18        super().tearDown()19    def verify_instance(self, name):20        self.assert_instance_command(21            name, "hbase {} -r {}".format(22                'org.apache.hadoop.hbase.IntegrationTestsDriver',23                'org.apache.hadoop.hbase.mapreduce.IntegrationTestImportTsv'))24    @parameterized.parameters(25        ("SINGLE", ["m"]),26        ("STANDARD", ["m"]),27        ("HA", ["m-0"]),28    )29    def test_hbase(self, configuration, machine_suffixes):30        # Skip on 2.0+ version of Dataproc because it's not supported31        if self.getImageVersion() >= pkg_resources.parse_version("2.0"):32            return33        init_actions = self.INIT_ACTIONS34        if configuration != "HA":35            init_actions = self.INIT_ACTIONS_FOR_NOT_HA + init_actions36        self.createCluster(configuration, init_actions)37        for machine_suffix in machine_suffixes:38            self.verify_instance("{}-{}".format(self.getClusterName(),39                                                machine_suffix))40    @parameterized.parameters(41        ("SINGLE", ["m"]),42        ("STANDARD", ["m"]),43        ("HA", ["m-0"]),44    )45    def test_hbase_on_gcs(self, configuration, machine_suffixes):46        # Skip on 2.0+ version of Dataproc because it's not supported47        if self.getImageVersion() >= pkg_resources.parse_version("2.0"):48            return49        init_actions = self.INIT_ACTIONS50        if configuration != "HA":51            init_actions = self.INIT_ACTIONS_FOR_NOT_HA + init_actions52        metadata = 'hbase-root-dir=gs://{}/test-dir'.format(self.GCS_BUCKET)53        if self.getImageVersion() > pkg_resources.parse_version("1.4"):54            self.initClusterName(configuration)55            hdfs_host = self.getClusterName()56            if configuration != "HA":57                hdfs_host += '-m'58            metadata += ',hbase-wal-dir=hdfs://{}/hbase-wal'.format(hdfs_host)59        self.createCluster(60            configuration,61            init_actions,62            metadata=metadata)63        for machine_suffix in machine_suffixes:64            self.verify_instance("{}-{}".format(self.getClusterName(),65                                                machine_suffix))66if __name__ == '__main__':...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!!
