Skip to content

Commit

Permalink
Remove pytest from testApp setup
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Dec 23, 2019
1 parent 32dc2a8 commit a994181
Show file tree
Hide file tree
Showing 29 changed files with 171 additions and 134 deletions.
12 changes: 6 additions & 6 deletions bin/running_stats.py
Expand Up @@ -15,11 +15,11 @@
package.delete()
package_stats.increment('deleted')
else:
package_stats.increment('not deleted')
package_stats.increment('not deleted')
print package_stats.report()
> deleted: 30
> not deleted: 70
from running_stats import StatsList
package_stats = StatsList()
for package in packages:
Expand All @@ -30,7 +30,7 @@
package_stats.add('not deleted' package.name)
print package_stats.report()
> deleted: 30 pollution-uk, flood-regions, river-quality, ...
> not deleted: 70 spending-bristol, ...
> not deleted: 70 spending-bristol, ...
'''

Expand All @@ -40,11 +40,11 @@ class StatsCount(dict):
# {category:count}
_init_value = 0
report_value_limit = 150

def _init_category(self, category):
if not self.has_key(category):
if category not in self:
self[category] = copy.deepcopy(self._init_value)

def increment(self, category):
self._init_category(category)
self[category] += 1
Expand Down
37 changes: 22 additions & 15 deletions ckan/i18n/check_po_files.py
Expand Up @@ -9,10 +9,12 @@
'''
import polib
import re
import paste.script.command

import six

if six.PY2:
import paste.script.command


def simple_conv_specs(s):
'''Return the simple Python string conversion specifiers in the string s.
Expand Down Expand Up @@ -50,23 +52,28 @@ def replacement_fields(s):
return sorted(repl_fields_re.findall(s))


class CheckPoFiles(paste.script.command.Command):
if six.PY2:
class CheckPoFiles(paste.script.command.Command):

usage = "[FILE] ..."
group_name = 'ckan'
summary = 'Check po files for common mistakes'
parser = paste.script.command.Command.standard_parser(verbose=True)

def command(self):
check_po_files(self.args)

usage = "[FILE] ..."
group_name = 'ckan'
summary = 'Check po files for common mistakes'
parser = paste.script.command.Command.standard_parser(verbose=True)

def command(self):
def check_po_files(paths):
for path in paths:
print(u'Checking file {}'.format(path))
errors = check_po_file(path)
if errors:
for msgid, msgstr in errors:
print("Format specifiers don't match:")
print(u' {0} -> {1}'.format(
msgid, msgstr.encode('ascii', 'replace')))

for path in self.args:
print(u'Checking file {}'.format(path))
errors = check_po_file(path)
if errors:
for msgid, msgstr in errors:
print("Format specifiers don't match:")
print(u' {0} -> {1}'.format(
msgid, msgstr.encode('ascii', 'replace')))


def check_po_file(path):
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/create_test_data.py
Expand Up @@ -157,7 +157,7 @@ def create_arbitrary(cls, package_dicts, relationships=[],
for item in package_dicts:
pkg_dict = {}
for field in cls.pkg_core_fields:
if item.has_key(field):
if field in item:
pkg_dict[field] = text_type(item[field])
if model.Package.by_name(pkg_dict['name']):
log.warning('Cannot create package "%s" as it already exists.' % \
Expand Down
4 changes: 2 additions & 2 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -411,7 +411,7 @@ def tag_list_dictize(tag_list, context):
# the same as its name, but the display_name might get changed later
# (e.g. translated into another language by the multilingual
# extension).
assert not dictized.has_key('display_name')
assert 'display_name' not in dictized
dictized['display_name'] = dictized['name']

if context.get('for_view'):
Expand Down Expand Up @@ -622,7 +622,7 @@ def make_api_2(package_id):

def vocabulary_dictize(vocabulary, context, include_datasets=False):
vocabulary_dict = d.table_dictize(vocabulary, context)
assert not vocabulary_dict.has_key('tags')
assert 'tags' not in vocabulary_dict

vocabulary_dict['tags'] = [tag_dictize(tag, context, include_datasets)
for tag in vocabulary.tags]
Expand Down
8 changes: 4 additions & 4 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -517,7 +517,7 @@ def activity_dict_save(activity_dict, context):
user_id = activity_dict['user_id']
object_id = activity_dict['object_id']
activity_type = activity_dict['activity_type']
if activity_dict.has_key('data'):
if 'data' in activity_dict:
data = activity_dict['data']
else:
data = None
Expand Down Expand Up @@ -554,7 +554,7 @@ def vocabulary_dict_save(vocabulary_dict, context):
vocabulary_obj = model.Vocabulary(vocabulary_name)
session.add(vocabulary_obj)

if vocabulary_dict.has_key('tags'):
if 'tags' in vocabulary_dict:
vocabulary_tag_list_save(vocabulary_dict['tags'], vocabulary_obj,
context)

Expand All @@ -567,10 +567,10 @@ def vocabulary_dict_update(vocabulary_dict, context):

vocabulary_obj = model.vocabulary.Vocabulary.get(vocabulary_dict['id'])

if vocabulary_dict.has_key('name'):
if 'name' in vocabulary_dict:
vocabulary_obj.name = vocabulary_dict['name']

if vocabulary_dict.has_key('tags'):
if 'tags' in vocabulary_dict:
vocabulary_tag_list_save(vocabulary_dict['tags'], vocabulary_obj,
context)

Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/lazyjson.py
Expand Up @@ -50,7 +50,7 @@ def method(self, *args, **kwargs):
for fn in [u'__contains__', u'__delitem__', u'__eq__', u'__ge__',
u'__getitem__', u'__gt__', u'__iter__', u'__le__', u'__len__',
u'__lt__', u'__ne__', u'__setitem__', u'clear', u'copy',
u'fromkeys', u'get', u'has_key', u'items', u'iteritems',
u'fromkeys', u'get', u'items', u'iteritems',
u'iterkeys', u'itervalues', u'keys', u'pop', u'popitem',
u'setdefault', u'update', u'values']:
setattr(LazyJSONObject, fn, _loads_method(fn))
4 changes: 2 additions & 2 deletions ckan/logic/action/__init__.py
Expand Up @@ -21,9 +21,9 @@ def rename_keys(dict_, key_map, reverse=False, destructive=False):
for key, mapping in key_map.items():
if reverse:
key, mapping = (mapping, key)
if (not destructive) and new_dict.has_key(mapping):
if (not destructive) and mapping in new_dict:
continue
if dict_.has_key(key):
if key in dict_:
value = dict_[key]
new_dict[mapping] = value
del new_dict[key]
Expand Down
4 changes: 2 additions & 2 deletions ckan/logic/action/delete.py
Expand Up @@ -594,7 +594,7 @@ def tag_delete(context, data_dict):
'''
model = context['model']

if not data_dict.has_key('id') or not data_dict['id']:
if 'id' not in data_dict or not data_dict['id']:
raise ValidationError({'id': _('id not in data')})
tag_id_or_name = _get_or_bust(data_dict, 'id')

Expand All @@ -614,7 +614,7 @@ def tag_delete(context, data_dict):
def _unfollow(context, data_dict, schema, FollowerClass):
model = context['model']

if not context.has_key('user'):
if 'user' not in context:
raise ckan.logic.NotAuthorized(
_("You must be logged in to unfollow something."))
userobj = model.User.get(context['user'])
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/action/update.py
Expand Up @@ -906,7 +906,7 @@ def vocabulary_update(context, data_dict):
raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)

data_dict['id'] = vocab.id
if data_dict.has_key('name'):
if 'name' in data_dict:
if data_dict['name'] == vocab.name:
del data_dict['name']

Expand Down
4 changes: 2 additions & 2 deletions ckan/logic/validators.py
Expand Up @@ -308,7 +308,7 @@ def object_id_validator(key, activity_dict, errors, context):
'''
activity_type = activity_dict[('activity_type',)]
if object_id_validators.has_key(activity_type):
if activity_type in object_id_validators:
object_id = activity_dict[('object_id',)]
return object_id_validators[activity_type](object_id, context)
else:
Expand Down Expand Up @@ -672,7 +672,7 @@ def tag_not_in_vocabulary(key, tag_dict, errors, context):
tag_name = tag_dict[('name',)]
if not tag_name:
raise Invalid(_('No tag name'))
if tag_dict.has_key(('vocabulary_id',)):
if ('vocabulary_id',) in tag_dict:
vocabulary_id = tag_dict[('vocabulary_id',)]
else:
vocabulary_id = None
Expand Down
8 changes: 5 additions & 3 deletions ckan/plugins/toolkit.py
Expand Up @@ -397,9 +397,11 @@ def _add_resource(cls, path, name):
absolute_path = os.path.join(this_dir, path)
create_library(name, absolute_path)

# TODO: remove next two lines after dropping Fanstatic support
import ckan.lib.fanstatic_resources
ckan.lib.fanstatic_resources.create_library(name, absolute_path)
import six
if six.PY2:
# TODO: remove next two lines after dropping Fanstatic support
import ckan.lib.fanstatic_resources
ckan.lib.fanstatic_resources.create_library(name, absolute_path)

@classmethod
def _add_ckan_admin_tabs(cls, config, route_name, tab_label,
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/snippets/search_form.html
Expand Up @@ -61,7 +61,7 @@ <h2>Error</h2>
<span class="facet">{{ facets.titles.get(field) }}:</span>
{% for value in facets.fields[field] %}
<span class="filtered pill">
{%- if facets.translated_fields and facets.translated_fields.has_key((field,value)) -%}
{%- if facets.translated_fields and (field,value) in facets.translated_fields -%}
{{ facets.translated_fields[(field,value)] }}
{%- else -%}
{{ h.list_dict_filter(search_facets_items, 'name', 'display_name', value) }}
Expand Down

0 comments on commit a994181

Please sign in to comment.