Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
 def test_class_method(self):
     Foo.DEPS[unittest.TestCase] = self
     foo = Foo()
     foo.foo() | should.be(self)
     foo.foo(test=None) | should.be_None
Ejemplo n.º 19
0
    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!')
Ejemplo n.º 20
0
    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')
Ejemplo n.º 21
0
 def test_class_constructor(self):
     Foo.DEPS[unittest.TestCase] = self
     foo = Foo()
     foo.test | should.be(self)
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
    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('不给')
Ejemplo n.º 24
0
 def test_inject_metaclass_default_value(self):
     self.foo.echo() | should.be(self.ham)
Ejemplo n.º 25
0
    def test_override_missing(self):
        @self.inject
        def foo(test=unittest.TestCase, missing=InjectorOverridesTests):
            return missing

        foo(missing=self) | should.be(self)
Ejemplo n.º 26
0
    def test_override_missing(self):
        @self.inject
        def foo(test=unittest.TestCase, missing=InjectorOverridesTests):
            return missing

        foo(missing=self) | should.be(self)
Ejemplo n.º 27
0
 def test_inject_metaclass_default_value(self):
     self.foo.echo() | should.be(self.ham)
Ejemplo n.º 28
0
    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)
Ejemplo n.º 29
0
 def test_chains_coroutines(self):
     self.pipeline()
     all_of(('FOO', 'BAR', 'BAZZ')) | should.be_in(self.recollector)
     len(self.recollector) | should.be(3)
Ejemplo n.º 30
0
 def test_class_constructor(self):
     Foo.DEPS[unittest.TestCase] = self
     foo = Foo()
     foo.test | should.be(self)
Ejemplo n.º 31
0
 def test_class_method(self):
     Foo.DEPS[unittest.TestCase] = self
     foo = Foo()
     foo.foo() | should.be(self)
     foo.foo(test=None) | should.be_None
Ejemplo n.º 32
0
 def test_chains_coroutines(self):
     self.pipeline()
     all_of(('FOO', 'BAR', 'BAZZ')) | should.be_in(self.recollector)
     len(self.recollector) | should.be(3)