class TestMain(unittest.TestCase): def setUp(self): self.emp_1 = Employee("José", "111.111.111-11", "2000.00") self.emp_2 = Employee("Mario", "444.444.444-44", "1800.00") self.emp_3 = Employee("César", "555.555.555-55", "2200.00") self.man_1 = Manager("Maria", "222.222.222-22", "5000.00", "3542", "3") self.man_2 = Manager("Paula", "666.666.666-66", "6000.00", "8546", "4") self.man_3 = Manager("Carolina", "777.777.777-77", "7000.00", "9852", "6") self.cli_1 = Client("Luiza", "333.333.333-33", "3854") def tearDown(self): pass def test_name(self): self.assertEqual(self.emp_1._name, "José") self.assertEqual(self.man_1._name, "Maria") self.assertEqual(self.cli_1._name, "Luiza") def test_get_bonus(self): self.assertEqual(self.emp_1.get_bonus(), 200) self.assertEqual(self.emp_2.get_bonus(), 180) self.assertEqual(self.emp_3.get_bonus(), 220) self.assertEqual(self.man_1.get_bonus(), 1500) self.assertEqual(self.man_2.get_bonus(), 1600) self.assertEqual(self.man_3.get_bonus(), 1700)
def test_first_line(): points = [ Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4), Point(5, 5), Point(6, 6) ] manager = Manager(points) manager.process() assert 1 == manager.count_line()
def test_4th_5th_lines(): points = [ Point(10, 1), Point(10, 2), Point(10, 3), Point(11, 4), Point(11, 5), Point(11, 6) ] manager = Manager(points) manager.process() assert 2 == manager.count_line()
def test_inherited_methods(self): manager = Manager(123, 123 , 123) manager.calc_bonus() manager.get_hours() manager.get_department() manager.set_department(None) seller = Seller(123, 123 , 123) seller.calc_bonus() seller.get_hours() seller.get_department() seller.set_department(None)
def test_2nd_3rd_lines(): points = [ Point(7, 1), Point(7, 2), Point(8, 3), Point(8, 4), Point(9, 5), Point(9, 6) ] manager = Manager(points) manager.process() assert 2 == manager.count_line()
class TestAbstract(unittest.TestCase): def setUp(self): self.manager_1 = Manager("Gabriela", "888.457.000-99", 6000.0, 4525, 4) self.manager_2 = Manager("Mariele", "147.354.025-55", 7000.0, 3654, 5) self.director_1 = Director("Marcia", "555.471.333-14", 4000.0) self.director_2 = Director("Vinicius", "333.014.982-00", 3000.0) def tearDown(self): pass def test_get_bonus(self): self.assertEqual(self.manager_1.get_bonus(), 1200) self.assertEqual(self.manager_2.get_bonus(), 1400) self.assertEqual(self.director_1.get_bonus(), 600) self.assertEqual(self.director_2.get_bonus(), 450)
def test_merge_lines(): points = [ Point(7, 1), Point(7, 2), Point(8, 3), Point(8, 4), Point(9, 5), Point(9, 6), Point(10, 1), Point(10, 2), Point(10, 3), Point(11, 4), Point(11, 5), Point(11, 6) ] manager = Manager(points) manager.process() assert 4 == manager.count_line()
def test_mandatory_methods(self): manager = Manager(123, 123 , 123) manager.get_department() manager.set_department(None) seller = Seller(123, 123 , 123) seller.get_department() seller.set_department(None)
def setUp(self): self.emp_1 = Employee("José", "111.111.111-11", "2000.00") self.emp_2 = Employee("Mario", "444.444.444-44", "1800.00") self.emp_3 = Employee("César", "555.555.555-55", "2200.00") self.man_1 = Manager("Maria", "222.222.222-22", "5000.00", "3542", "3") self.man_2 = Manager("Paula", "666.666.666-66", "6000.00", "8546", "4") self.man_3 = Manager("Carolina", "777.777.777-77", "7000.00", "9852", "6") self.cli_1 = Client("Luiza", "333.333.333-33", "3854")
def test_least_lines(): points = [ Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4), Point(5, 5), Point(6, 6), Point(7, 1), Point(7, 2), Point(8, 3), Point(8, 4), Point(9, 5), Point(9, 6), Point(10, 1), Point(10, 2), Point(10, 3), Point(11, 4), Point(11, 5), Point(11, 6) ] manager = Manager(points) manager.process() assert 5 == manager.count_line()
class Server(object): def __init__(self): self.manager = Manager() @cherrypy.expose() def index(self): with open("static/index.html", "r") as f: content = f.read() return content @cherrypy.expose() def filter(self, searchstr="", page_size=10, page_number=1): return json.dumps( self.manager.filter_results(searchstr, page_number=page_number, page_size=page_size))
def test_set_get_department_name(self): manager = Manager(123, 123 , 123) old_dep_name = manager.get_department() new_dep_name = 'top_managers' manager.set_department(new_dep_name) assert manager.get_department() != old_dep_name assert manager.get_department() == new_dep_name seller = Seller(123, 123 , 123) old_dep_name = seller.get_department() new_dep_name = 'top_sellers' seller.set_department(new_dep_name) assert seller.get_department() != old_dep_name assert seller.get_department() == new_dep_name
def test_manager_class(self): manager = Manager(123, 123, 123) with pytest.raises(AttributeError): manager.department.name
def main(): """Do stuff.""" args = FLAGS.parse_args() if args.mode == 'pack': assert args.packlist and args.maskloc dataset2masks = {} dataset2classifiers = {} net_type = None # Location to output stats. fout = open(args.maskloc[:-2] + 'txt', 'w') # Load models one by one and store their masks. fin = open(args.packlist, 'r') counter = 1 for idx, line in enumerate(fin): if not line or not line.strip() or line[0] == '#': continue dataset, loadname = line.split(':') loadname = loadname.strip() # Can't have same dataset twice. if dataset in dataset2masks: ValueError('Repeated datasets as input...') print('Loading model #%d for dataset "%s"' % (counter, dataset)) counter += 1 ckpt = torch.load(loadname) model = ckpt['model'] # Ensure all inputs are for same model type. if net_type is None: net_type = str(type(model)) else: assert net_type == str(type(model)), '%s != %s' % ( net_type, str(type(model))) # Gather masks and store in dictionary. fout.write('Dataset: %s\n' % (dataset)) total_params, neg_params, zerod_params = [], [], [] masks = {} for module_idx, module in enumerate(model.shared.modules()): if 'ElementWise' in str(type(module)): mask = module.threshold_fn(module.mask_real) mask = mask.data.cpu() # Make sure mask values are in {0, 1} or {-1, 0, 1}. num_zero = mask.eq(0).sum() num_one = mask.eq(1).sum() num_mone = mask.eq(-1).sum() total = mask.numel() threshold_type = module.threshold_fn.__class__.__name__ if threshold_type == 'Binarizer': assert num_mone == 0 assert num_zero + num_one == total elif threshold_type == 'Ternarizer': assert num_mone + num_zero + num_one == total masks[module_idx] = mask.type(torch.ByteTensor) # Count total and zerod out params. total_params.append(total) zerod_params.append(num_zero) neg_params.append(num_mone) fout.write('%d\t%.2f%%\t%.2f%%\n' % ( module_idx, neg_params[-1] / total_params[-1] * 100, zerod_params[-1] / total_params[-1] * 100)) print('Check Passed: Masks only have binary/ternary values.') dataset2masks[dataset] = masks dataset2classifiers[dataset] = model.classifier fout.write('Total -1: %d/%d = %.2f%%\n' % ( sum(neg_params), sum(total_params), sum(neg_params) / sum(total_params) * 100)) fout.write('Total 0: %d/%d = %.2f%%\n' % ( sum(zerod_params), sum(total_params), sum(zerod_params) / sum(total_params) * 100)) fout.write('-' * 20 + '\n') # Clean up and save masks to file. fin.close() fout.close() torch.save({ 'dataset2masks': dataset2masks, 'dataset2classifiers': dataset2classifiers, }, args.maskloc) elif args.mode == 'eval': assert args.arch and args.maskloc and args.dataset # Set default train and test path if not provided as input. utils.set_dataset_paths(args) # Load masks and classifier for this dataset. info = torch.load(args.maskloc) if args.dataset not in info['dataset2masks']: ValueError('%s not found in masks.' % (args.dataset)) masks = info['dataset2masks'][args.dataset] classifier = info['dataset2classifiers'][args.dataset] # Create the vanilla model and apply masking. model = None if args.arch == 'vgg16': model = net.ModifiedVGG16(original=True) elif args.arch == 'vgg16bn': model = net.ModifiedVGG16BN(original=True) elif args.arch == 'resnet50': model = net.ModifiedResNet(original=True) elif args.arch == 'densenet121': model = net.ModifiedDenseNet(original=True) elif args.arch == 'resnet50_diff': assert args.source model = net.ResNetDiffInit(args.source, original=True) model.eval() print('Applying masks.') for module_idx, module in enumerate(model.shared.modules()): if module_idx in masks: mask = masks[module_idx] module.weight.data[mask.eq(0)] = 0 module.weight.data[mask.eq(-1)] *= -1 print('Applied masks.') # Override model.classifier with saved one. model.add_dataset(args.dataset, classifier.weight.size(0)) model.set_dataset(args.dataset) model.classifier = classifier if args.cuda: model = model.cuda() # Create the manager and run eval. manager = Manager(args, model) manager.eval()
#!/usr/bin/env python # -*- coding: utf-8 -*- # author: [email protected] import argparse from main import Manager if __name__ == "__main__": parser = argparse.ArgumentParser(prog="odoh", description='Odoo helper functions', epilog=""" For more info call help on each option : odoh symlink -h """) parser.add_argument('action', help='Repo action') #parser.add_argument('-a', '--action', nargs='+', help='Repos actions') parser.add_argument('-c', '--config', help=' optional custom config to run') parser.add_argument('-r', '--repos', nargs='+', help='Repos config for run') args = vars(parser.parse_args()) manager = Manager(args) # manager.process()
from main import Employee, Manager, Bonus_Control, Client if __name__ == '__main__': employee = Employee("João", "111.111.111-11", "2000.00") print(f"Employee bonus: {employee.get_bonus()}") manager1 = Manager("Helena", "222.222.222-22", "5000.00", "1234", "0") print(f"Manager bonus: {manager1.get_bonus()}") manager2 = Manager("Isabel", "333.333.333-33", "5000.00", "1245", "0") print(f"Manager bonus: {manager2.get_bonus()}") client1 = Client("Marisa", "444.444.444-44", "8721") control = Bonus_Control() control.register(employee) control.register(manager1) control.register(manager2) control.register(client1) print(f"Total: {control.bonus_total}")
def test_workload_hours(self): manager = Manager(123, 123 , 123) assert manager.get_hours() == 8 seller = Seller(123, 123 , 123) assert seller.get_hours() == 8
def setUp(self): self.manager_1 = Manager("Gabriela", "888.457.000-99", 6000.0, 4525, 4) self.manager_2 = Manager("Mariele", "147.354.025-55", 7000.0, 3654, 5) self.director_1 = Director("Marcia", "555.471.333-14", 4000.0) self.director_2 = Director("Vinicius", "333.014.982-00", 3000.0)
def test_simple_line(): points = [Point(1, 1), Point(2, 2), Point(3, 3)] manager = Manager(points) manager.process() assert 1 == manager.count_line()
def __init__(self): self.manager = Manager()