def test_class_descriptor(self): egg = Eggs() spam = egg.bar() spam | should.be_a(Spam) spam_again = egg.bar() spam_again | should.be(spam) egg.bar() | should.be(spam)
def createWorkspaceForSpace(self, spaceID): print('Creating workspace.....') theToken = helpers.get_user_tokens().split(";")[0] authHeader = 'Bearer {}'.format(theToken) headers = { 'Accept': 'application/json', 'Authorization': authHeader, 'X-App': 'OSIO', 'X-Git-Provider': 'GitHub', 'Content-Type': 'application/json' } print('Looking for codebases of space: {}'.format(spaceID)) r = requests.get('{}/api/spaces/{}/codebases'.format( apiAddress, spaceID), headers=headers) r.status_code | should.be(200).desc( "Status code for response to get space codebases is 200.") cbId = r.json()["data"][0]["id"] try: r = requests.post('{}/api/codebases/{}/create'.format( apiAddress, cbId), data="", headers=headers) respJson = r.json() # print (respJson) workspaceLink = respJson["links"]["open"] print('Workspace created at {}'.format(workspaceLink)) print('Looking for workspaces of codebase: {}'.format(cbId)) r = requests.get('{}/api/codebases/{}/workspaces'.format( apiAddress, cbId), headers=headers) r.status_code | should.be(200).desc( "Status code for response to get codebase workspaces is 200.") ws = r.json()["data"][0] wsId = ws["attributes"]["id"] wsName = ws["attributes"]["name"] print("Workspace ID (name): {} ({})".format(wsId, wsName)) print("Starting workspace") r = requests.post( '{}/api/workspace/{}/runtime?environment=default'.format( cheApiAddress, wsId), data='{}', headers=headers) print('Starting workspace response: [{}]'.format(r.text)) return wsId except Exception as e: print('Unexpected error found: {}'.format(e)) return None
def test_executes_catch_only_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield v = value.to_xxx() if destination is not None: destination.send(v) class Foo(object): def __init__(self, value): self.value = value def to_xxx(self): return self def __repr__(self): return self.value register(to_xxx) values = (Foo('10'), Foo('20'), Foo('30'), '1', '2') _pipeline = (pipeline((x for x in values)).to_xxx().catch( collect(self.recollector)).collect(self.recollector)) _pipeline() all_of([x for (i, x) in enumerate(values) if i < 4]) | should.be_in( self.recollector) len(self.recollector) | should.be(4)
def test_override_from_calling_site(self): @self.inject def foo(test=unittest.TestCase): return test foo() | should.be(self) foo(test=True) | should.be_True
def test_override_from_updated_map(self): @self.inject def foo(test=unittest.TestCase): return test foo() | should.be(self) self.map[unittest.TestCase] = True foo() | should.be_True
def test_warns_when_unneeded(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") foo = self.inject(lambda: True) w | should.have_len(1) w[0].category | should.be(UserWarning)
def test_override_injector_unitestingmode(self): egg = Eggs() spam = egg.bar() spam | should.be_a(Spam) spam_again = egg.bar() spam_again | should.be(spam) # without unit testing the instance keeps the first assignment spam = egg.bar() Eggs.DEPS._singletons.clear() egg = Eggs() spam_again = egg.bar() spam_again | should.not_be(spam)
def test_deprecated_property(self): @self.inject def test(foo=InjectorPatchTests): return foo self.inject.dependencies = {InjectorPatchTests: 'foo'} with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") test() | should.eql('foo') w | should.have_len(1) w[0].category | should.be(UserWarning)
def test_executes_catch_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield value.to_xxx() register(to_xxx) _pipeline = (pipeline( (x for x in ('foo', 'bar', 'bazz'))).uppercase().to_xxx().catch( collect(self.recollector))) _pipeline() 'FOO' | should.be_in(self.recollector) len(self.recollector) | should.be(1)
def test_executes_catch_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield value.to_xxx() register(to_xxx) _pipeline = ( pipeline((x for x in ('foo', 'bar', 'bazz'))) .uppercase() .to_xxx() .catch(collect(self.recollector)) ) _pipeline() 'FOO' | should.be_in(self.recollector) len(self.recollector) | should.be(1)
def test_executes_catch_only_upon_exception_raised(self): @coroutine def to_xxx(destination=None): while True: value = yield v = value.to_xxx() if destination is not None: destination.send(v) class Foo(object): def __init__(self, value): self.value = value def to_xxx(self): return self def __repr__(self): return self.value register(to_xxx) values = (Foo('10'), Foo('20'), Foo('30'), '1', '2') _pipeline = ( pipeline((x for x in values)) .to_xxx() .catch(collect(self.recollector)) .collect(self.recollector) ) _pipeline() all_of( [x for (i, x) in enumerate(values) if i < 4] ) | should.be_in(self.recollector) len(self.recollector) | should.be(4)
def test_class_method(self): Foo.DEPS[unittest.TestCase] = self foo = Foo() foo.foo() | should.be(self) foo.foo(test=None) | should.be_None
def removeSpaces(self): # Tokens are stored in a form of "<access_token>;<refresh_token>(;<username>)" theToken = helpers.get_user_tokens().split(";")[0] print('Starting removing spaces.....') spacesIDs = self.getSpaces() print('Number of spaces before removing: {}'.format(len(spacesIDs))) serverAddress = os.getenv("WIT_API") cheAddress = os.getenv("CHE_API") authHeader = 'Bearer {}'.format(theToken) headers = { 'Accept': 'application/json', 'Authorization': authHeader, 'X-App': 'OSIO', 'X-Git-Provider': 'GitHub', 'Content-Type': 'application/json' } # delete spaces for spaceID in spacesIDs: print('Looking for codebases of space: {}'.format(spaceID)) r = requests.get('{}/api/spaces/{}/codebases'.format( serverAddress, spaceID), headers=headers) r.status_code | should.be(200).desc( "Status code for response to get space codebases is 200.") codebases = r.json()["data"] if codebases is not None: for cb in codebases: cbID = cb["id"] print( 'Looking for workspaces of codebase: {}'.format(cbID)) r = requests.get('{}/api/codebases/{}/workspaces'.format( serverAddress, cbID), headers=headers) r.status_code | should.be(200).desc( "Status code for response to get codebase workspaces is 200." ) workspaces = r.json()["data"] if workspaces is not None: for ws in workspaces: wsID = ws["attributes"]["id"] wsName = ws["attributes"]["name"] print('Deleting workspace: {} ({})'.format( wsID, wsName)) r = requests.delete('{}/api/workspace/{}'.format( cheAddress, wsID), headers=headers) r.status_code | should.be(204).desc( "Status code for response to delete workspace is 204." ) else: print("No workspaces found.") else: print("No codebases found.") print('Deleting space {}'.format(spaceID)) r = requests.delete('{}/api/spaces/{}'.format( serverAddress, spaceID), headers=headers) r.status_code | should.be(200).desc( "Status code for response to delete space is 200.") if r.status_code != 200: print( "ERROR - Request to delete space {} failed - error code = {}" .format(spaceID, r.status_code)) print('Number of spaces after removing: {}'.format( len(self.getSpaces()))) print('Spaces removed!')
def Dtest_rf(self): chooseBestFeatureToSplit(self.data) | should.be(0) tree = createTree(self.data, ['喉结', '胡子']) tree | should.eq({'喉结': {0: {'胡子': {0: 'female', 1: 'male'}}, 1: 'male'}}) classify(tree, ['喉结', '胡子'], [0, 0]) | should.be('female')
def test_class_constructor(self): Foo.DEPS[unittest.TestCase] = self foo = Foo() foo.test | should.be(self)
def test_no_injectable_params(self): foo = self.inject(lambda: True, __warn__=False) foo() | should.be_True foo = self.inject(lambda x: x, __warn__=False) foo(10) | should.be(10)
def test_rf2(self): text = ''' 年龄, 工作, 已婚, 信用, 可以借贷? 青年, no , no , 一般 , 不给 青年, no , no , 好 , 不给 青年, yes, no , 好 , 给 青年, yes, yes, 一般 , 给 青年, no , no , 一般 , 不给 中年, no , no , 一般 , 不给 中年, no , no , 好 , 不给 中年, yes, yes, 好 , 给 中年, no , yes, 非常好 , 给 中年, no , yes, 非常好 , 给 老年, no , yes, 非常好 , 给 老年, no , yes, 好 , 给 老年, yes, no , 好 , 给 老年, yes, no , 非常好 , 给 老年, no , no , 一般 , 不给 ''' from pprint import pprint data, title = datamatrix(text) n = chooseBestFeatureToSplit(data) tree = createTree(data, title) n | should.be(2) tree | should.eq({'已婚': {'no': {'工作': {'no': '不给', 'yes': '给'}}, 'yes': '给'}}) test1 = classify(tree, ['年龄', '工作', '已婚', '信用'], ['青年', 'no', 'no', '好']) test2 = classify(tree, ['年龄', '工作', '已婚', '信用'], ['青年', 'no', 'yes', '非常好']) test3 = classify(tree, ['年龄', '工作', '已婚', '信用'], ['老年', 'yes','yes', '一般']) test4 = classify(tree, ['年龄', '工作', '已婚', '信用'], ['老年', 'no', 'no', '好']) test1 | should.eq('不给') test2 | should.eq('给') test3 | should.eq('给') test4 | should.eq('不给') data, title = datamatrix(text) dt = DecisionTree(data, labels=title) n = dt.best_split_feature(data) tree = dt.decision_tree print(n) pprint(tree) test1 = dt.classify(['青年', 'no', 'no', '好'], decision_tree=tree) test2 = dt.classify(['青年', 'no', 'yes', '非常好'], decision_tree=tree) test3 = dt.classify(['老年', 'yes','yes', '一般'], decision_tree=tree) test4 = dt.classify(['老年', 'no', 'no', '好'], decision_tree=tree) test1 | should.eq('不给') test2 | should.eq('给') test3 | should.eq('给') test4 | should.eq('不给')
def test_inject_metaclass_default_value(self): self.foo.echo() | should.be(self.ham)
def test_override_missing(self): @self.inject def foo(test=unittest.TestCase, missing=InjectorOverridesTests): return missing foo(missing=self) | should.be(self)
def test_no_injectable_params(self): foo = self.inject(lambda: True, warn=False) foo() | should.be_True foo = self.inject(lambda x: x, warn=False) foo(10) | should.be(10)
def test_chains_coroutines(self): self.pipeline() all_of(('FOO', 'BAR', 'BAZZ')) | should.be_in(self.recollector) len(self.recollector) | should.be(3)