Running Python unittests from Command Line

This script will allow a Python unittest to be run from the command line. import unittest import testFile suite = unittest.TestLoader().loadTestsFromModule(testFile) unittest.TextTestRunner().run(suite) testFile.py import unittest from fun import add class test_function(unittest.TestCase): def test_one(self): result = add(2,3) self.assertEquals(result, 5) fun.py def add(a,b): return a+b

Simple Python Unit Test

This simple Python unit-test tests two function. The first function adds two numbers and the second function uses list comprehensions to make a list of numbers from to 0 to n which are divisible by m. testFile.py import unittest from add import addition, make_list class test_add_function(unittest.TestCase): def test_for_add(self): result = addition(1, 5) self.assertEqual(result, 6) def…Read More

Angular Service Example

The following code demonstrates how a service can be created in AngularJS. index.html <html> <head> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js”></script> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js”></script> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.min.js”></script> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.min.js”></script> <script src=”app.js”></script> <script src=”anotherModule.js”></script> </head> <body> <div ng-app=”mainModule” ng-controller=”mainController as alias”> <b>Invoice:</b> <p>The input is: {{alias.quantity}}</p> <div> Quantity: <input type=”number” min=”0″ ng-model=”alias.quantity”required> </div> <div><p>Add 4 and double it!</p></div> <div> <b>Result:</b> <span>{{alias.total(alias.quantity)}}</span> <button…Read More

Install Mongodb on Fedora 23

To install Mongodb on Fedora 23 go to https://www.mongodb.org/downloads On the Linux tab go to version RHEL 7 Linux 64-bit $ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.3.tgz Untar the tarball $ tar -zxvf mongodb-linux-x86_64-rhel70-3.2.3.tgz $ echo $PATH $ sudo ln -s ~/Downloads/mongodb-linux-x86_64-rhel70-3.2.3/bin/mongo /usr/local/bin/mongod $ mongod –version MongoDB shell version: 3.2.3 $ mongo –version MongoDB shell version: 3.0.8 Make the…Read More