Skip to content

Commit

Permalink
Add python 2 backward compatiblity
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed May 18, 2017
1 parent 821ce08 commit 1dfd7f7
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ target/

# pyenv python configuration file
.python-version

#pycharm
.idea*
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
language: python
matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 3.3
env: TOXENV=py33
- python: 3.4
Expand All @@ -14,14 +16,14 @@ matrix:
env: TOXENV=py36

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
install:
- pip install -U tox
- pip install tox codecov coveralls
- pip install -r requirements.txt
- pip install pytest-cov

# command to run tests, e.g. python setup.py test
script:
script:
- py.test --cov=ippy tests/
- tox -e ${TOXENV}

Expand Down
7 changes: 4 additions & 3 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ History

* Add readme.rst

0.2.0 (2017-05-14)
0.2.3 (2017-05-14)
------------------

* Add unittests
* Improve test coverage

0.2.1 (2017-05-14)
0.3.0 (2017-05-14)
------------------

* Improve test coverage
* Add python 2 backward compatibility
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Parallel testing of IP addresses and domains in python.
Reads IP addresses and domains from a CSV file and gives two lists of accessible and inaccessible ones.

## About
- Written in Python 3
- Testing of IPs and domains is done in parallel.
- Compatible with both Python 2 and 3.
- Testing of IPs and domains is done in parallel.
- By default there are 4 Workers.
- All Workers work on an input Queue and a output Queue.

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and inaccessible ones.
About
-----

- Written in Python 3
- Compatible with both Python 2 and 3.
- Testing of IPs and domains is done in parallel.
- By default there are 4 Workers.
- All Workers work on an input Queue and a output Queue.
Expand Down Expand Up @@ -75,4 +75,4 @@ then run tox from the project root directory.

::

$ tox
$ tox
8 changes: 7 additions & 1 deletion examples/example1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future.standard_library import install_aliases
from ippy import ippy
import sys

Expand All @@ -14,4 +19,5 @@ def main():
print(output)

if __name__ == "__main__":
install_aliases()
sys.exit(main())
8 changes: 7 additions & 1 deletion examples/example2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future.standard_library import install_aliases
from ippy import ippy
import sys

Expand All @@ -14,4 +19,5 @@ def main():
print(output)

if __name__ == "__main__":
install_aliases()
sys.exit(main())
2 changes: 1 addition & 1 deletion ippy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__author__ = """Shivam Mathur"""
__email__ = 'shivam_jpr@hotmail.com'
__version__ = '0.2.3'
__version__ = '0.3.0'

from .ippy import Ippy
20 changes: 15 additions & 5 deletions ippy/ippy.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Python script to check if IP address and domains are accessible or not.
.. codeauthor:: Shivam Mathur <shivam_jpr@hotmail.com>
"""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future.standard_library import install_aliases
from io import StringIO
from json import dumps
from csv import writer
from itertools import zip_longest
from future.moves.itertools import zip_longest

import sys
import os
import platform
import subprocess
import threading
import queue
import pingparsing
import queue


class Ippy(object):
Expand Down Expand Up @@ -185,10 +189,16 @@ def result(self):
result = dumps(result_dict, indent=4)
elif self.output == 'csv':
result = StringIO()
writer(result)
ippy_writer = writer(result)
d = [self._accessible, self._not_accessible]
for x in zip_longest(*d):
ippy_writer.writerow(x)
result = result.getvalue().strip('\r\n')
result = 'Accessible,Not Accessible\n' + result
else:
raise ValueError("Unknown output mode")

return result

if __name__ == "__main__":
install_aliases()
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pingparsing==0.6.0

pingparsing>=0.6.0

future>=0.16.0
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.3
current_version = 0.3.0
commit = True
tag = True

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

setup(
name='ippy',
version='0.2.3',
version='0.3.0',
description="Parallel testing of IP addresses and domains in python.",
author="Shivam Mathur",
author_email='shivam_jpr@hotmail.com',
url='https://github.com/shivammathur/ippy',
download_url='https://github.com/shivammathur/ippy/archive/0.2.3.tar.gz',
download_url='https://github.com/shivammathur/ippy/archive/0.3.0.tar.gz',
packages=[
'ippy',
],
Expand All @@ -42,10 +42,11 @@
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Networking",
Expand Down
18 changes: 14 additions & 4 deletions tests/test_ippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
Tests for `ippy` module.
"""
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import pytest
from future.standard_library import install_aliases
from ippy import ippy
import pytest
import sys
import os
import json
from io import StringIO
from csv import reader
install_aliases()


def test_config():
Expand Down Expand Up @@ -43,7 +49,8 @@ def test_ping_args():
ping_args = ippt.get_ping_args("Linux")
assert ping_args == ["ping", "-c", "2", "-l", "1", "-s", "1", "-W", "2"]

pytest.raises(ValueError, "ippt.get_ping_args('Test')")
with pytest.raises(ValueError):
ippt.get_ping_args('Test')


def test_filepath():
Expand Down Expand Up @@ -72,20 +79,23 @@ def test_empty_result():
ippt.set_config(False, 'test', 10)
ippt.set_file(file='ip_list.csv')
ippt.run()
pytest.raises(ValueError, "ippt.result()")
with pytest.raises(ValueError):
ippt.result()


def test_json_result():
ippt = ippy.Ippy()
ippt.set_config(False, 'json', 10)
result = ippt.result()
assert json.loads(result) is not None


def test_csv_result():
ippt = ippy.Ippy()
ippt.set_config(False, 'csv', 10)
result = ippt.result()
my_result = StringIO(result)
my_reader = reader(my_result, delimiter=',')
my_reader = reader(my_result, delimiter=str(','))
csv_result = ''
for row in my_reader:
for cell in row:
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py33, py34, py35, py36
envlist = py27, py33, py34, py35, py36

[testenv]
setenv =
Expand All @@ -9,9 +9,9 @@ deps =
-r{toxinidir}/requirements.txt
codecov>=1.4.0
coveralls
passenv = CI TRAVIS TRAVIS_*
passenv = CI TRAVIS TRAVIS_*
commands =
pip install -U pip
py.test --basetemp={envtmpdir}
codecov -e TOXENV
codecov -e TOXENV
coveralls

0 comments on commit 1dfd7f7

Please sign in to comment.