Example #1
0
    def test_multi_level(self):
        base = self.simple_base
        base.a = 1

        extend = prototype(base).new
        extend.b = 2

        further = prototype(extend).new
        further.c = 3

        sibling = prototype(extend).new
        sibling.d = 4

        baby = prototype(sibling).new
        baby.e = 5

        assert base.a == extend.a == further.a == sibling.a == baby.a == 1
        assert extend.b == further.b == sibling.b == baby.b == 2
        assert further.c == 3
        try:
            sibling.c
            assert False
        except:
            pass
        try:
            baby.c
        except:
            pass

        assert sibling.d == baby.d == 4
        assert baby.e == 5
    def test_multi_level(self):
        base = self.simple_base
        base.a = 1
        
        extend = prototype(base).new
        extend.b = 2

        further = prototype(extend).new
        further.c = 3
        
        sibling = prototype(extend).new
        sibling.d = 4

        baby = prototype(sibling).new
        baby.e = 5
        
        assert base.a == extend.a == further.a == sibling.a == baby.a == 1
        assert extend.b == further.b == sibling.b == baby.b == 2
        assert further.c == 3
        try:
            sibling.c
            assert False
        except:
            pass
        try:
            baby.c
        except:
            pass

        assert sibling.d == baby.d == 4
        assert baby.e == 5
    def test_mock(self):
        assert self.base

        sub = prototype(self.base)
        return #TODO: make this work
        print len(sub)

        assert len(sub) == len(self.base)
Example #4
0
    def test_mock(self):
        assert self.base

        sub = prototype(self.base)
        return  #TODO: make this work
        print len(sub)

        assert len(sub) == len(self.base)
    def test_instance_is_dynamic(self):
        base = self.base
        base.test = 0
        extend = prototype(base)
        assert extend.test == base.test == 0, "testing basic fallback"

        base.test = 1
        assert extend.test == base.test == 1, "testing dynamic fallback"
        assert base.base_list == ['init']
Example #6
0
    def test_instance_is_dynamic(self):
        base = self.base
        base.test = 0
        extend = prototype(base)
        assert extend.test == base.test == 0, "testing basic fallback"

        base.test = 1
        assert extend.test == base.test == 1, "testing dynamic fallback"
        assert base.base_list == ['init']
    def test_instance(self):
        base = self.base
        base.base_test = 0

        extend = prototype(base)
        extend.test = 1

        assert extend.base_test == base.base_test == 0, "testing fallback"
        assert extend.test == 1, "testing basic setting"
        assert extend.test2 == 'test2', "testing fallback"
        assert base.test == 'test', "ensuring property didn't propagate up"
        assert base.base_list == ['init', 'test2', 'test']
Example #8
0
    def test_instance(self):
        base = self.base
        base.base_test = 0

        extend = prototype(base)
        extend.test = 1

        assert extend.base_test == base.base_test == 0, "testing fallback"
        assert extend.test == 1, "testing basic setting"
        assert extend.test2 == 'test2', "testing fallback"
        assert base.test == 'test', "ensuring property didn't propagate up"
        assert base.base_list == ['init', 'test2', 'test']
    def test_existing_new_works(self):
        base = self.base
        base.new = 5
        base.bar = 6
        extend = prototype(base)
        try:
            extend.bar
            assert False, "you can't use magic new removal if base has a new"
        except PrototypeException:
            pass

        assert isinstance(extend, PrototypeSwitcher), "prototype switching"
        extend2 = extend.new
        assert not isinstance(extend2, PrototypeSwitcher), "switch worked"
        assert extend2.bar == base.bar == 6, "switched instance prototypes corerctly"
        extend3 = extend.new
        assert id(extend2) == id(extend3), "news are singletons"
Example #10
0
    def test_existing_new_works(self):
        base = self.base
        base.new = 5
        base.bar = 6
        extend = prototype(base)
        try:
            extend.bar
            assert False, "you can't use magic new removal if base has a new"
        except PrototypeException:
            pass

        assert isinstance(extend, PrototypeSwitcher), "prototype switching"
        extend2 = extend.new
        assert not isinstance(extend2, PrototypeSwitcher), "switch worked"
        assert extend2.bar == base.bar == 6, "switched instance prototypes corerctly"
        extend3 = extend.new
        assert id(extend2) == id(extend3), "news are singletons"
    def test_instance_not_defined(self):
        base = self.simple_base
        base.test = 5
        extend = prototype(base)
        extend.extend_test = 42

        assert base.test == extend.test == 5, "simple fallback"
        try:
            extend.foo
            assert False, "extend.foo should raise an exception"
        except AttributeError:
            pass

        assert extend.extend_test == 42, "basic setting"
        try:
            base.extend_test
            assert False, "base.extend_test shouldn't be set (propagation)"
        except AttributeError:
            pass
Example #12
0
    def test_instance_not_defined(self):
        base = self.simple_base
        base.test = 5
        extend = prototype(base)
        extend.extend_test = 42

        assert base.test == extend.test == 5, "simple fallback"
        try:
            extend.foo
            assert False, "extend.foo should raise an exception"
        except AttributeError:
            pass

        assert extend.extend_test == 42, "basic setting"
        try:
            base.extend_test
            assert False, "base.extend_test shouldn't be set (propagation)"
        except AttributeError:
            pass
    def test_functions_work(self):
        import new
        base = self.base
        def id(self, x):
            return x

        base.id = new.instancemethod(id, base)
        base.id(5)
    
        extend = prototype(base)
        
        extend.incr = lambda x: x + 1 #try adding a classmethod

        def incr2(self, x):
            return x + 2
        
        extend.incr2 = new.instancemethod(incr2, extend) #and a bound method
        
        assert base.id(5) == extend.id(5) == 5, "fallback instance methods work"
        assert extend.incr(5) == 6, "bound class methods work"
        assert extend.incr2(5) == 7, "bound instance methods work"
Example #14
0
    def test_functions_work(self):
        import new
        base = self.base

        def id(self, x):
            return x

        base.id = new.instancemethod(id, base)
        base.id(5)

        extend = prototype(base)

        extend.incr = lambda x: x + 1  #try adding a classmethod

        def incr2(self, x):
            return x + 2

        extend.incr2 = new.instancemethod(incr2, extend)  #and a bound method

        assert base.id(5) == extend.id(
            5) == 5, "fallback instance methods work"
        assert extend.incr(5) == 6, "bound class methods work"
        assert extend.incr2(5) == 7, "bound instance methods work"
Example #15
0
Y_train = np.load(os.path.join(path, f'{dataset_name}_Y_TRAIN.npy'))
X_test = np.load(os.path.join(path, f'{dataset_name}_X_TEST.npy'))
Y_test = np.load(os.path.join(path, f'{dataset_name}_Y_TEST.npy'))

# ADAPT DATA TO ONE-CLASS CLASSIFICATION

print('AVAILABLE CLASSES: ', np.unique(Y_train))

positive = 1  # Choose a positive class
print('POSITVE CLASS: ', positive)
X_train = X_train[(Y_train == positive)]
Y_test = (Y_test == positive).astype(np.int8)

# SELECT DISS. MEASURE and PROTOTYPE METHOD

D, P = dissimilarity(), prototype()

Dissimilarity = D.kullback_leibler
diss_params = {}
# OR
#Dissimilarity = D.EDR # This is fairly slow
#diss_params = {'eps':0.25} # Threshold on distance for EDR computation

Prot_method = P.borders
# OR
#Prot_method = P.centers_k_means

# GET DISSIMILARITY MATRIX

# Some prototype methods eg "centers_k_means" do not require
# the computation of the dissimilarity matrix
Example #16
0
#!/usr/bin/env python2

# Used to test the functionality of "prototype.py", which contains various size metrics
# computed on a given github repository.

from prototype import prototype

repos = [
    "https://github.com/octocat/Spoon-Knife.git",
#    "https://github.com/django/django.git",
    "https://github.com/joyent/node.git",
    "https://github.com/mono/mono.git",
    "https://github.com/ruby/ruby.git",
    "https://github.com/python-git/python.git",
    "https://github.com/mirrors/gcc.git",
    "https://github.com/pld-linux/koffice.git",
    "https://github.com/GNOME/gimp.git",
    "https://github.com/chromium/chromium.git",
    "https://github.com/linuxmint/Cinnamon.git",
    "https://github.com/torvalds/linux.git",
    "https://github.com/apache/hadoop-common.git",
    "https://github.com/visionmedia/express.git",
    "https://github.com/freebsd/freebsd.git",
]

for repo in repos:
    monoRepo = prototype()
    monoRepo.init(repo)
    monoRepo.printStats()