holidays / holidays

A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

There is no (documented?) way to run the tests on a custom file

richdrich opened this issue · comments

If I define a custom test stanza in my yaml file, there is no way to run it after a:

Holidays.load_custom('/home/user/holiday_definitions/custom_holidays.yaml')

(or this isn't documented?).

Sorry for my lazy response.
In my view, there is no way to run test in custom yaml file.
@ppeble Any ideas?

Sorry for the incredible delay. I'm getting back into a rhythm for responding to issues but that doesn't help things from the past. ☹️

@richdrich The short answer is 'no', there is no way to run tests against custom files. That's because in my original conception of 'custom' definitions they are only loaded at runtime and therefore 'tests' don't really play into how they are used.

If you are willing could you maybe provide a use case of your workflow where being able to run tests is useful? I'm definitely willing to amend the current setup to allow it if I better understand how it would add value. 👍

So we (at Sharesight) use the holidays gem to track when a stock market is expected to be open and send us prices.

Because stock market holidays don't (often) match a national or regional holiday, we've created custom regions for each one and added the exceptions to them. It would be good if we could also add some tests to these files (as for the standard holidays) then we could test them using your mechanism (instead, we just have some tests that call date.holiday? for known dates).

I think it would be a nice feature, but it isn't a biggie for us.

@richdrich This makes a lot of sense to me in principle (I love enabling more tests!) but I'm having trouble understanding the actual workflow you would use. Were you envisioning something like a separate rake task that could be given the custom defs (with tests) and have the defined tests run on them?

As an example of what I am thinking, I wrote a test_region rake task to help me when I wanted to test out specific regions. I think it would be pretty straightforward to whip something up that would accept your desired custom definition files, parse and process them, and then execute the defined tests.

To be honest, I've been chomping at the bit for a reason to refactor that Rakefile. It has a lot of logic in it that I would love to be moved into the main lib directory. So I would be up for doing this if you thought it was useful to your workflow.

I was thinking I'd do this from our application's tests (we have our config yaml files in the app) so something like:

should 'have valid holday config` do
  assert Holidays.test_custom('config/holidays/custom_holidays.yaml')
end

with test_custom returning true if it passes, or logging reasons and returning false otherwise?

Oooh, that's interesting. That option didn't occur to me. I would have to think about how to run the tests (we use test-unit) in-process rather than letting them run via rakefile as a separate command. We already parse the defs and the tests but then throw the tests away. I'm sure it's possible...

I am always willing to look for more options in testing definitions so I think this is worthwhile to pursue. Let me think about this for a bit and get back to you. 👍

It,s interesting. :)