<commit_before># -*- coding: utf-8 -*-

import mock


class MockerResourceWithNetworkClient(object):

	resource_module = None

	mock_fluent_request_class = None

	@classmethod
	def setup_method(cls):

		# there are several similar modules-resources.
		# all we need to test them -- mock NetworkClient, to prevent
		# network access.
		# Let's do it with mock.patch.object
		#
		# Mocked client will be accessible in tests as `cls.client`

		# mock FluentRequest
		cls._patcher_fluent_request_class = mock.patch(
			'route4me.sdk._net.FluentRequest'
		)
		cls.mock_fluent_request_class = cls._patcher_fluent_request_class.start()

	@classmethod
	def teardown_method(cls):
		"""Teardown test environment for the entire class
		"""
		cls._patcher_fluent_request_class.stop()

	def set_response(self, status_code=200, data=None, **qw):

		x = mock.MagicMock()
		x.status_code = status_code
		x.json.return_value = data

		for k in qw:
			x.k = qw[k]

		self.mock_fluent_request_class.return_value.send.return_value = x

	def last_request(self):
		return self.mock_fluent_request_class.return_value
<commit_msg>test: fix tests for python3<commit_after># -*- coding: utf-8 -*-

import mock


class MockerResourceWithNetworkClient(object):

	resource_module = None

	mock_fluent_request_class = None

	@classmethod
	def setup_method(cls, *args, **qw):

		# there are several similar modules-resources.
		# all we need to test them -- mock NetworkClient, to prevent
		# network access.
		# Let's do it with mock.patch.object
		#
		# Mocked client will be accessible in tests as `cls.client`

		# mock FluentRequest
		cls._patcher_fluent_request_class = mock.patch(
			'route4me.sdk._net.FluentRequest'
		)
		cls.mock_fluent_request_class = cls._patcher_fluent_request_class.start()

	@classmethod
	def teardown_method(cls, *args, **qw):
		"""Teardown test environment for the entire class
		"""
		cls._patcher_fluent_request_class.stop()

	def set_response(self, status_code=200, data=None, **qw):

		x = mock.MagicMock()
		x.status_code = status_code
		x.json.return_value = data

		for k in qw:
			x.k = qw[k]

		self.mock_fluent_request_class.return_value.send.return_value = x

	def last_request(self):
		return self.mock_fluent_request_class.return_value

{'fraction_non_alphanumeric': 0.09724689165186501, 'fraction_numerical': 0.004884547069271759, 'mean_word_length': 4.326241134751773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2101085', 'n_tokens_mistral': 843, 'n_tokens_neox': 760, 'n_words': 180}