def test_contains_int(self): b = Bureau(User) agent = User(15) b.add(agent) assert 15 in b assert 16 not in b
def test_del_agent(self): b = Bureau(User) agent = User(0) b.add(agent) b.remove(0) assert agent not in b assert 0 not in b._agents
def test_add_agent(self): b = Bureau(User) agent = User(0) b.add(agent) assert agent in b assert 0 in b._agents assert b.get(0) == agent
def test_export_contents(self): b = Bureau(User) for i in range(10): b.add(User(i)) export = b.export() pprint(export) assert b.export()[0] == User(0).export() assert b.export()[5] == User(5).export()
def __init__(self): """ Initialize SWAP instance Args: p0: Prior probability real - in general this is derived empirically by considering the occurence frequency of interesting objects that are expertly identified within a fiducial dataset. It is required to initialize the likelihood formulation framework for each subject prior to reception of the first volunteer classification. epsilon: Estimated volunteer performance - This is either set arbitrarily or might be based upon judicious assesment of cohort-wide volunteer performance on a similar analysis task. It is required to initialize the likelihood formulation framework for each volunteer's agent. """ # initialize bureaus to manage user / subject agents self.users = Bureau(User) self.subjects = Bureau(Subject)
def test_notify(self, mock): l = Ledger(15) t = Transaction(mock(), 0) print(mock().id) l.add(t) l.clear_changes() l.notify(16, Bureau(Subject)) t.notify.assert_called_once_with(mock()) assert l.stale is True assert l.changed == [16]
def __init__(self, t_low, t_high, export=None): golds = gold_0 + gold_1 self.golds = db.getExpertGold(golds) self.silver = self.golds.copy() self.t_low = t_low self.t_high = t_high self.bureau = Bureau(Bootstrap_Subject) self.metrics = Metrics() self.n = 0
def test_bureau_stats(self): b = Bureau(User) b.add(User(0)) b.add(User(1)) b.add(User(2)) for u in b: u.ledger.recalculate() s = b.stats() assert 0 in s.stats assert 1 in s.stats assert len(s.stats) == 2
def test_get_agent_new(self): b = Bureau(User) u = b.get(15) assert type(u) is User assert u.id == 15
def test_notify_agents_getsagent(self, mock): l = Ledger(100) _ = [l.add(Transaction(mocksubject(i), 0)) for i in range(5)] l.notify_agents(None, Bureau(User)) assert mock.call_count == 5
def test_contains_true(self): b = Bureau(User) agent = User(15) b.add(agent) assert agent in b
def test_has_false(self): b = Bureau(User) assert 0 not in b
def test_has_true(self): b = Bureau(User) agent = User(0) b.add(agent) assert agent in b
def test_idset(self): b = Bureau(User) [b.add(User(i)) for i in range(5)] assert b.idset() == set(range(5))
def test_get_agent_none(self): b = Bureau(User) assert b.get(0, make_new=False) is None
def test_stats_subject(self): b = Bureau(Subject) [b.add(Subject(i)) for i in range(5)] [s.ledger.recalculate() for s in b] b.stats()
def test_contains_false(self): b = Bureau(User) agent = User(15) assert agent not in b
def test_get_agent(self): b = Bureau(User) agent = User(0) b.add(agent) assert b.get(0) == agent
def test_add_agent_twice_new(self): b = Bureau(User) agent = User(0) b.add(agent) b.add(agent, override=True)
def test_add_agent_twice_nonew(self): b = Bureau(User) agent = User(0) b.add(agent) with pytest.raises(KeyError): b.add(agent, override=False)
def test_add_agent_typecheck(self): b = Bureau(User) agent = Subject(0) with pytest.raises(TypeError): b.add(agent)
def test_init(self): b = Bureau(Agent) assert b.agent_type is Agent assert b._agents == {}
def get_bureau(self): b = Bureau(Subject) for i in range(5): b.add(Subject(i)) return b
def test_get_newagent_isadded(self): b = Bureau(User) u = b.get(15) assert u in b assert b.get(15) == u
def test_stats_users(self): b = Bureau(User) [b.add(User(i)) for i in range(5)] [u.ledger.recalculate() for u in b] b.stats()