Month-over-Month data in Splunk

Categories: 

I've been working with Splunk Enterprise a lot lately (and it's very powerful and easy to use!). In many situations, it is useful to show some metric compared to the same metric a month ago (or some other time period).

One way to accomplish this is with the community-supported Splunk app, Timewrap. I couldn't get Timewrap to output the data as I wanted, so instead here's the approach that I used.

Note to self: Always version-lock your dependencies!

Categories: 

Background:

I was setting up a development copy of a client website on my computer the other day, and after I had cloned the repo, set up the database, and pip installed Django and all of the other python packages needed for the website, I faced a strange Exception coming from deep inside of one of my dependencies. After an embarrasingly long period of troubleshooting, I realized that when I specified my python dependencies, I neglected to include the version requirements for each package.

Problem:

Mocking datetime in Python 2

Categories: 

Mocking dates is a well-known PITA with Python. But here's a quick explanation of how I worked around this deficiency.


Step 1: Add the date as a property to the production class. I had to refactor my code, and I suspect you will too. Before mocking this date, I was calling date.today() from the build_widget method.

from datetime import date

class WidgetWorker(object):
    date = date.today()
    def build_widget(self):
        return {'date_created': self.date}

How to Test Assertions are Raised or Handled in Python

When unit testing Python, how can one assert that exceptions are raised or handled? Here's how we do it:

First, here is the code we want to test:

def division_raises():
    print(10/0)


def division_doesnt_raise():
    try:
        print(10/0)
    except ZeroDivisionError:
        return None

And here is how we test the code above:

Pages

Subscribe to Pixelchef.net RSS