Loading

How to share your code with pip

xavierval

This is a live streamed presentation. You will automatically follow the presenter and see the slide they're currently on.

How to share and reuse your testing

 tools and utils code
(in Python)

Light Talks

Code tricks.

[fiware-iotqaUtils]

aka:

WHY

we need this?

How many times have you said:

 This code would be useful for the rest of my team but i will show it for the next sprint, right?

 This code is not part of the functionality that I am testing...
I will add it to my "Utils" library. 

So...

  • How many "Utils" libs have you local files pending of be reviewed?
     
  • Did you share it with any of your team? 
     
  • Are the rest of your team reusing your code?

Let us show you

how we did it

What was our case

@industrial_IoT

We were

(at the beginning of the platform approx)

  • 5 Teams
  • 8 Components
  • 5 Component QAs
  • 2 Platform QA

We needed to

  • Reuse the code of the QA-components
     
  • Have an easy way to share our Utils libs
     
  • Centralised QA Utils repository 

How we did it

 

 


(may be it is not the best way but it worked for us)

Ingredients:

(Just 3 steps)

  • Create a new repository
     
  • Create a setup.py
     
  • Use and share your utils :)
     

Create a new repository

Now that it is created

Add a setup.py

#!/usr/bin/env python

from setuptools import setup

setup(
    name='commonUtils',
    version='0.0.1',
    description='common Utilities',
    url='https://github.com/XavierVal/commonUtils',
    install_requires=[
        'requests==1.2.3',
        'nose==1.3.4'
    ],
    py_modules=[
        'commonUtils.time_utils',
    ],
    packages=[
        'commonUtils',
        'commonUtils.templates',
    ],
)

Submit your utils
(This one is no so useful... but it is just an example)

from datetime import datetime


class TimeUtils(object):

    def time_now(self):
        current_time = datetime.now().time()
        print "Current Time is: {}".format(current_time)
        return current_time

Install your new lib

$   pip install git+https://github.com/XavierVal/commonUtils@master

Downloading/unpacking git+https://github.com/XavierVal/commonUtils@master
  Cloning https://github.com/XavierVal/commonUtils (to master) to c:\users\x\appdata\local\temp\pip-8iwi5h-build
  Running setup.py (path:c:\users\x\appdata\local\temp\pip-8iwi5h-build\setup.py) egg_info for package from git+https://github.com/XavierVal/commonUtils@master
Requirement already satisfied (use --upgrade to upgrade): requests==1.2.3 in c:\python27\lib\site-packages (from commonUtils==0.0.1)
Requirement already satisfied (use --upgrade to upgrade): nose==1.3.4 in c:\python27\lib\site-packages (from commonUtils==0.0.1)
Installing collected packages: commonUtils
  Running setup.py install for commonUtils
Successfully installed commonUtils
Cleaning up...



$ pip list | grep common
commonUtils (0.0.1)

Now you can use and share and your library with just a pip install 

$ python

>>> from commonUtils import time_utils

>>> time_obj = time_utils.TimeUtils()

>>> time_obj.time_now()
Current Time is: 09:44:14.066000

Sample repositories:

Silly sample

  • https://github.com/XavierVal/commonUtils

Links & Resources

IotpQAUtils 

  • https://pdihub.hi.inet/fiware/fiware-iotqaUtils

What we

have now

Thanks!! 

Made with Slides.com