Skip to content

Commit

Permalink
Make python-untraceables python 3 compatible (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersmitten authored Mar 30, 2020
1 parent aea9e28 commit 2b74f37
Show file tree
Hide file tree
Showing 22 changed files with 1,241 additions and 1,237 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python

python:
- "2.7"
- "3.5"

services:
- mysql
Expand All @@ -26,6 +27,6 @@ script:

notifications:
email: false
hipchat:
slack:
rooms:
secure: X5mHSHzsNBgQNKnwIFuSzagSHUqyPLGWL1SW6aMHRd4WtdAEtfN3w+iyvT1s0v7F4p9xZc3PEzV8WbXtsELkDEnYvLyucS8MVMQJ1ohuDig32t4TIwMnEZF0IyhDTlUtG31wnLWxxM0Kmx+/6xrg7I9tx2EA0w2opof2K1cHBVARFEq/sFBF/bOthLfR9dM4paAkELZMgg/CsK4T9S9SWo4NsvwUbP3bWV3Gh6dYF3g5nd7DhqxUvusL9oMu5JXA5U4H7dCB7aQRAjg12Fdg/F/ZJelVT+Deg3zGHep8zTEr4ykVWpoVko6VK9+Jh8WSnazG7XCEMNNatmR48CTXuoj5axLTjP0yyfeniauIFwapO3jaf+Vn/HOAa3xNQz/MBg24J9P74CCeYDJ18uu5WqcNetpw/re4N6edPGWBfbk332JoMvPU47RlX24n6rxghO62zA4wf/uohmeEdqxlDIfeofPeCKBuxeMT/wAVKxFB75fmBlrAQcGQuVgvfRLOEUb1ONTFsl4RaTSIRsxFivRCWp5jUeUp4BxYYKpFKhBawIvaFQtriy/PbTZUBlBmOATGmpAL/bgmfuEWKTZ8uVJYkj/VoI36C6hqWbzJKuxzWn7tFeeQC2dcSpdhZx7aacdhEGYlv00v9X+AIXSGxNhQIIraGkEsvqqj2F2kag4=
secure: "4/IX3mVZcuDbPszD3zRgcu3FLWQafgaWdj7jZ+J9xdt94j0rtlanw3cCifed8+RXtarIGQUk1mUt6UXF9wdG3lgaS3zCLAXJfkyBs/i8gKOUQRWpDATpFCkPGOyz2FcYKLAdefkMQz8SmrJ5aLVb20jqxYAsgs8SNsrf3z7LrAeOY8tCPgBVXSQjIGfU8TckEObDLuIdZcPrVgGRoHcT2kBMQk4dlcosChlItv7pi/dB6svJM89Nrv1QRd644NNRwslQ2+jw2CPitbHbRrEWjp0NRg18e9io0P7iMOnrRjuWPhY6+3Nzxv7/q9IO2rK4zXxGK4rlJNMC/61qYb1Khak0eeLhUaatsQaIpPTXG30SEYvIyZpNJQGpawN3dyBTQW17D4kBni/N9ruXs+rhYve/k7WS2I1BjrDellHmIJ4PT/Y5pOAx5HE00w1f00K3LZLaBizhU/R7WzRgbhQjqO2RyItZZGG0fX0lcyUVRP5RPFJAPDX5M8vYyfT/HWLB80q1PSY8Zt+x0vVOtkzqmQkfBnr1hx9XYlT9zbkBs1tw8UxsDYQC2f+aXFKtq0EHBDijCWy05VEGIR+WwID9MHBLrd+EYec713DVrk7TFwI34t3izfhSaU0novOdZqpliqKepBnF92FNKRj5nQ1UEKjDgqat2bm26MhR43+tnH0="
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## Requirements

* Python 2.7
* Python 3.5

## Usage

Expand Down
456 changes: 228 additions & 228 deletions bin/randomize-ids

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

max-line-length=120

indent-string=' '
indent-string=' '

[TYPECHECK]
ignored-classes=MySQLdb
9 changes: 4 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
configobj==5.0.6
mycli==1.18.2
MySQL-python==1.2.5
mycli==1.20.1
mysqlclient==1.4.6
nose==1.3.7
pep8==1.7.1
pycodestyle==2.4.0
pylint==1.9.3
pycodestyle==2.5.0
pylint==1.9.5
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configobj==5.0.6
MySQL-python==1.2.5
mysqlclient==1.4.6
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from setuptools import setup, find_packages


def readme():
with open('README.md') as f:
return f.read()
with open('README.md') as f:
return f.read()


setup(name='untraceables',
Expand Down
117 changes: 59 additions & 58 deletions untraceables/test/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import os
import unittest

Expand All @@ -8,64 +9,64 @@

class TestConfiguration(unittest.TestCase):

def test_read_file(self):
"""
Tests `read_file`.
"""

filename = 'lorem'
actual = configuration_utility.read_file(filename)
self.assertFalse(actual)

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'untraceables.cfg')
actual = configuration_utility.read_file(filename)
expected = 'configobj.ConfigObj'
self.assertTrue(expected in str(type(actual)))
expected = 'lorem'
self.assertEqual(expected, actual['main']['host'])
expected = 'ipsum'
self.assertEqual(expected, actual['main']['user'])
expected = 'dolor'
self.assertEqual(expected, actual['main']['password'])

def test_read_file(self):
"""
Tests `read_xclude_regexes_file`.
Non-existing file.
"""

expected = []
actual = configuration_utility.read_xclude_regexes_file('lorem')
self.assertEqual(expected, actual)

def test_read_file_0(self):
"""
Tests `read_xclude_regexes_file`.
Non-empty file.
"""

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'include-from-0')
expected = [r'^audit_trails\.user_id$',
r'^audit_trails\..*user_id$',
r'^tickets\.user_id$',
r'^tickets\..*user_id$',
r'^users\.id$',
r'^users\.user_id$',
r'^users\..*user_id$']
actual = configuration_utility.read_xclude_regexes_file(filename)

def test_read_file_1(self):
"""
Tests `read_xclude_regexes_file`.
Empty file.
"""

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'include-from-1')
expected = []
actual = configuration_utility.read_xclude_regexes_file(filename)
def test_read_file(self):
"""
Tests `read_file`.
"""

filename = 'lorem'
actual = configuration_utility.read_file(filename)
self.assertFalse(actual)

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'untraceables.cfg')
actual = configuration_utility.read_file(filename)
expected = 'configobj.ConfigObj'
self.assertTrue(expected in str(type(actual)))
expected = 'lorem'
self.assertEqual(expected, actual['main']['host'])
expected = 'ipsum'
self.assertEqual(expected, actual['main']['user'])
expected = 'dolor'
self.assertEqual(expected, actual['main']['password'])

def test_read_file(self):
"""
Tests `read_xclude_regexes_file`.
Non-existing file.
"""

expected = []
actual = configuration_utility.read_xclude_regexes_file('lorem')
self.assertEqual(expected, actual)

def test_read_file_0(self):
"""
Tests `read_xclude_regexes_file`.
Non-empty file.
"""

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'include-from-0')
expected = [r'^audit_trails\.user_id$',
r'^audit_trails\..*user_id$',
r'^tickets\.user_id$',
r'^tickets\..*user_id$',
r'^users\.id$',
r'^users\.user_id$',
r'^users\..*user_id$']
actual = configuration_utility.read_xclude_regexes_file(filename)

def test_read_file_1(self):
"""
Tests `read_xclude_regexes_file`.
Empty file.
"""

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'include-from-1')
expected = []
actual = configuration_utility.read_xclude_regexes_file(filename)


suite = unittest.TestLoader().loadTestsFromTestCase(TestConfiguration)
Expand Down
34 changes: 17 additions & 17 deletions untraceables/test/test_file.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import os
import unittest

from untraceables.utilities import file as file_utility


class TestFile(unittest.TestCase):

def test_get_sorted_file_list(self):
"""
Tests `get_sorted_file_list`.
"""

path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
expected = ['include-from-0', 'include-from-1',
'test_split_file_0.sql', 'test_split_file_1.sql', 'test_split_file_2.sql',
'untraceables.cfg']
actual = file_utility.get_sorted_file_list(path)
self.assertEquals(expected, list(actual))

path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data-non-existing')
expected = []
actual = file_utility.get_sorted_file_list(path)
self.assertEquals(expected, list(actual))
def test_get_sorted_file_list(self):
"""
Tests `get_sorted_file_list`.
"""

path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
expected = ['include-from-0', 'include-from-1',
'test_split_file_0.sql', 'test_split_file_1.sql', 'test_split_file_2.sql',
'untraceables.cfg']
actual = file_utility.get_sorted_file_list(path)
self.assertEquals(expected, list(actual))

path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data-non-existing')
expected = []
actual = file_utility.get_sorted_file_list(path)
self.assertEquals(expected, list(actual))


suite = unittest.TestLoader().loadTestsFromTestCase(TestFile)
Expand Down
130 changes: 65 additions & 65 deletions untraceables/test/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import unittest

from untraceables.utilities import filter as filter_utility


class TestFilter(unittest.TestCase):

def test_show_tables(self):
"""
Tests `show_tables`.
"""

table_columns = iter([])
inclusive_regexes = exclusive_regexes = []
expected = set([])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = exclusive_regexes = []
expected = set([])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = [r'^.*\..*$']
exclusive_regexes = []
expected = set(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = [r'^.*\..*$']
exclusive_regexes = [r'^sit\..*$']
expected = set(['ipsum.dolor', 'consectetur.adipiscing'])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = [r'^.*\..*$']
exclusive_regexes = [r'^.*\.adipiscing$']
expected = set(['ipsum.dolor', 'sit.amet'])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

def test_table_names_from_mydumper_backup(self):
"""
Tests `table_names_from_mydumper_backup`.
"""

files = []
suffixed_database = 'ipsum.'
expected = []
actual = filter_utility.table_names_from_mydumper_backup(files, suffixed_database)
self.assertTrue(hasattr(actual, 'next'))
self.assertEquals(expected, list(actual))

files = ['ipsum.dolor-schema.sql', 'ipsum.dolor.sql',
'ipsum.consectetur-schema.sql', 'ipsum.consectetur.sql']
suffixed_database = 'ipsum.'
expected = ['ipsum.dolor.sql', 'ipsum.consectetur.sql']
actual = filter_utility.table_names_from_mydumper_backup(files, suffixed_database)
self.assertTrue(hasattr(actual, 'next'))
self.assertEquals(expected, list(actual))

files = ['ipsum.dolor-schema.sql', 'ipsum.dolor.sql',
'consectetur.adipiscing-schema.sql', 'consectetur.adipiscing.sql']
suffixed_database = 'ipsum.'
expected = ['ipsum.dolor.sql']
actual = filter_utility.table_names_from_mydumper_backup(files, suffixed_database)
self.assertEquals(expected, list(actual))
def test_show_tables(self):
"""
Tests `show_tables`.
"""

table_columns = iter([])
inclusive_regexes = exclusive_regexes = []
expected = set([])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = exclusive_regexes = []
expected = set([])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = [r'^.*\..*$']
exclusive_regexes = []
expected = set(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = [r'^.*\..*$']
exclusive_regexes = [r'^sit\..*$']
expected = set(['ipsum.dolor', 'consectetur.adipiscing'])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

table_columns = iter(['ipsum.dolor', 'sit.amet', 'consectetur.adipiscing'])
inclusive_regexes = [r'^.*\..*$']
exclusive_regexes = [r'^.*\.adipiscing$']
expected = set(['ipsum.dolor', 'sit.amet'])
actual = filter_utility.show_tables(table_columns, inclusive_regexes, exclusive_regexes)
self.assertEquals(expected, actual)

def test_table_names_from_mydumper_backup(self):
"""
Tests `table_names_from_mydumper_backup`.
"""

files = []
suffixed_database = 'ipsum.'
expected = []
actual = filter_utility.table_names_from_mydumper_backup(files, suffixed_database)
self.assertTrue(hasattr(actual, 'next') or hasattr(actual, '__next__'))
self.assertEquals(expected, list(actual))

files = ['ipsum.dolor-schema.sql', 'ipsum.dolor.sql',
'ipsum.consectetur-schema.sql', 'ipsum.consectetur.sql']
suffixed_database = 'ipsum.'
expected = ['ipsum.dolor.sql', 'ipsum.consectetur.sql']
actual = filter_utility.table_names_from_mydumper_backup(files, suffixed_database)
self.assertTrue(hasattr(actual, 'next') or hasattr(actual, '__next__'))
self.assertEquals(expected, list(actual))

files = ['ipsum.dolor-schema.sql', 'ipsum.dolor.sql',
'consectetur.adipiscing-schema.sql', 'consectetur.adipiscing.sql']
suffixed_database = 'ipsum.'
expected = ['ipsum.dolor.sql']
actual = filter_utility.table_names_from_mydumper_backup(files, suffixed_database)
self.assertEquals(expected, list(actual))


suite = unittest.TestLoader().loadTestsFromTestCase(TestFilter)
Expand Down
Loading

0 comments on commit 2b74f37

Please sign in to comment.