def test__write__new_timestamp_queried_for_each_value(self): writer = self.MockBufferedTagWriter(Mock(ITimeStamper), 3) item = object() writer.mock_create_item.configure_mock(side_effect=None, return_value=item) writer.mock_buffer_value.configure_mock(side_effect=None) timestamp_property = PropertyMock( return_value=datetime.datetime.now(datetime.timezone.utc)) type(writer.time_stamper).timestamp = timestamp_property writer.write("tag", tbase.DataType.BOOLEAN, False, timestamp=None) timestamp_property.assert_called_once_with() timestamp_property.reset_mock() writer.write("tag", tbase.DataType.BOOLEAN, False, timestamp=None) timestamp_property.assert_called_once_with()
def test_creates_and_caches_proxy_objects(self): connection = Mock() p = PropertyMock(return_value='Account') type(connection).Account = p oc = amaxa.Operation(connection) proxy = oc.get_proxy_object('Account') self.assertEqual('Account', proxy) p.assert_called_once_with() p.reset_mock() proxy = oc.get_proxy_object('Account') # Proxy should be cached self.assertEqual('Account', proxy) p.assert_not_called()
def test_get_sentiment_scores(self, mock_text_blob_class): """ Tests if compute_average_sentiment method calls appropriate methods """ tweets_sentiment.TweetsSentiment.get_sentiment_scores(tweets=[]) self.assertEqual(0, mock_text_blob_class.call_count) mock_text_blob = mock_text_blob_class.return_value mock_polarity = PropertyMock() mock_sentiment = PropertyMock() type(mock_text_blob).sentiment = mock_sentiment type(mock_text_blob.sentiment).polarity = mock_polarity mock_sentiment.reset_mock() tweets_sentiment.TweetsSentiment.get_sentiment_scores( tweets=['tweet1', 'tweet2']) self.assertEqual(2, mock_text_blob_class.call_count) self.assertEqual(2, mock_sentiment.call_count) self.assertEqual(2, mock_polarity.call_count)