Skip to content

Commit b2f5c41

Browse files
committed
Do not test import for coverage
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent bdc74eb commit b2f5c41

File tree

6 files changed

+40
-36
lines changed

6 files changed

+40
-36
lines changed

src/attributecode/__init__.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import os
2424

2525
try:
26-
unicode # Python 2
27-
except NameError:
28-
unicode = str # Python 3 #NOQA
26+
# Python 2
27+
unicode
28+
except NameError: # pragma: nocover
29+
# Python 3
30+
unicode = str #NOQA
2931

3032

3133
__version__ = '3.3.0'
@@ -53,17 +55,17 @@ class Error(namedtuple('Error', ['severity', 'message'])):
5355
def __new__(self, severity, message):
5456
if message:
5557
if isinstance(message, unicode):
56-
message = clean_string(message)
58+
message = self._clean_string(message)
5759
else:
58-
message = clean_string(unicode(repr(message), encoding='utf-8'))
60+
message = self._clean_string(unicode(repr(message), encoding='utf-8'))
5961
message = message.strip('"')
6062

6163
return super(Error, self).__new__(
6264
Error, severity, message)
6365

6466
def __repr__(self, *args, **kwargs):
6567
sev = severities[self.severity]
66-
msg = clean_string(repr(self.message))
68+
msg = self._clean_string(repr(self.message))
6769
return 'Error(%(sev)s, %(msg)s)' % locals()
6870

6971
def to_dict(self, *args, **kwargs):
@@ -72,26 +74,26 @@ def to_dict(self, *args, **kwargs):
7274
"""
7375
return self._asdict()
7476

75-
76-
def clean_string(s):
77-
"""
78-
Return a cleaned string for `s`, stripping eventual "u" prefixes
79-
from unicode representations.
80-
"""
81-
if not s:
77+
@staticmethod
78+
def _clean_string(s):
79+
"""
80+
Return a cleaned string for `s`, stripping eventual "u" prefixes
81+
from unicode representations.
82+
"""
83+
if not s:
84+
return s
85+
if s.startswith(('u"', "u'")):
86+
s = s.lstrip('u')
87+
s = s.replace('[u"', '["')
88+
s = s.replace("[u'", "['")
89+
s = s.replace("(u'", "('")
90+
s = s.replace("(u'", "('")
91+
s = s.replace("{u'", "{'")
92+
s = s.replace("{u'", "{'")
93+
s = s.replace(" u'", " '")
94+
s = s.replace(" u'", " '")
95+
s = s.replace("\\\\", "\\")
8296
return s
83-
if s.startswith(('u"', "u'")):
84-
s = s.lstrip('u')
85-
s = s.replace('[u"', '["')
86-
s = s.replace("[u'", "['")
87-
s = s.replace("(u'", "('")
88-
s = s.replace("(u'", "('")
89-
s = s.replace("{u'", "{'")
90-
s = s.replace("{u'", "{'")
91-
s = s.replace(" u'", " '")
92-
s = s.replace(" u'", " '")
93-
s = s.replace("\\\\", "\\")
94-
return s
9597

9698

9799
# modeled after the logging levels

src/attributecode/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
from __future__ import unicode_literals
2020

2121

22-
if __name__ == '__main__':
22+
if __name__ == '__main__': # pragma: nocover
2323
from attributecode import cmd
2424
cmd.cli()

src/attributecode/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
from attributecode.util import python2
2626

2727

28-
if python2:
28+
if python2: # pragma: nocover
2929
from urllib import quote # NOQA
3030
from urllib import urlencode # NOQA
3131
from urllib2 import HTTPError # NOQA
3232
from urllib2 import Request # NOQA
3333
from urllib2 import urlopen # NOQA
34-
else:
34+
else: # pragma: nocover
3535
from urllib.parse import quote # NOQA
3636
from urllib.parse import urlencode # NOQA
3737
from urllib.request import Request # NOQA

src/attributecode/gen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
from attributecode.util import unique
4242

4343

44-
if python2:
44+
if python2: # pragma: nocover
4545
import backports.csv as csv # NOQA
46-
else:
46+
else: # pragma: nocover
4747
import csv # NOQA
4848

4949

@@ -100,7 +100,7 @@ def check_duplicated_about_file_path(inventory_dict):
100100
afp_list.append(component['about_file_path'])
101101
return errors
102102

103-
#TODO: this should be either the CSV or the ABOUT files but not both???
103+
# TODO: this should be either the CSV or the ABOUT files but not both???
104104
def load_inventory(location, base_dir, license_notice_text_location=None,
105105
mapping_file=None):
106106
"""

src/attributecode/model.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@
3737

3838
import yaml
3939
import re
40-
import sys
4140

42-
if sys.version_info[0] < 3: # Python 2
41+
from attributecode.util import python2
42+
43+
44+
if python2: # pragma: nocover
4345
import backports.csv as csv # NOQA
4446
from itertools import izip_longest as zip_longest # NOQA
4547
from urlparse import urljoin, urlparse # NOQA
4648
from urllib2 import urlopen, Request, HTTPError # NOQA
47-
else: # Python 3
49+
else: # pragma: nocover
4850
basestring = str # NOQA
4951
import csv # NOQA
5052
from itertools import zip_longest # NOQA

src/attributecode/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434

3535
python2 = sys.version_info[0] < 3
3636

37-
if python2:
37+
if python2: # pragma: nocover
3838
import backports.csv as csv # NOQA
3939
from itertools import izip_longest as zip_longest # NOQA
40-
else:
40+
else: # pragma: nocover
4141
import csv # NOQA
4242
from itertools import zip_longest # NOQA
4343

0 commit comments

Comments
 (0)