Skip to content

Conversation

@Cheukting
Copy link
Contributor

@Cheukting Cheukting commented Dec 6, 2017

London Sprint #339

Pushing function resolve_imaginary in tz, created 4 test cases which 3 of them pass. the only one that fail is testMonroviaForward which is dealing with + 44mins 30seconds time zone changes. Further testing suggest that utcoffset ignore the 30seconds so it 0:30 on 7 Jan 1972 will become 1:14, not 1:14:30 on the same day.

"dateutil/test/test_tz.py::TzWinTest::testTzwinName": true,
"dateutil/test/test_tz.py::imaginaryDateTest::testMonroviaForward": true,
"dateutil/test/test_utils.py": true
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cache files generally don’t belong in the commit. Is this here intentionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are automatically generated during testing, can be deleted. I will have to tidy things up and push it again.

pass

def resolve_imaginary(dt):
import pdb;pdb.set_trace()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Pdb needed outside of testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was finishing in a rush, should be for testing only, I can tidy it up and push it again.

@pganssle pganssle added this to the 2.7.0 milestone Dec 7, 2017
@pganssle
Copy link
Member

@Cheukting FYI, it's generally not a great idea to work in the master branch of your fork. It's fine in this case, but it will make it harder to work in the future.

@Cheukting
Copy link
Contributor Author

Thanks @pganssle for the tip. I am new in term of developing packages so still need to learn what's the best practice. Will create a new branch next time. 😃

Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, I'd like to say thank you so much for your contribution. Even if you make no further changes to this PR, I am happy to clone your branch and make the changes I'd like before merging.

I have made a few stylistic notes about this PR - these are basically nitpicks, but I feel that it would be doing you a disservice if I did not give you feedback about the preferred style (since that's the way you find out what people expect). As I mention above, I'm happy to fix all the nitpicks myself.

You also found a new bug in dateutil (#582)! So that's a good thing!

One other thing is that there are a few more tests to add:

  1. Add a test with a 1-hour offset that takes place in the northern hemisphere.
  2. Add a test for Europe/London (which is an unusual zone).
  3. Add a test for something in the eastern hemisphere (maybe Europe/Kiev)
  4. Add two tests that this returns the same object during an ambiguous time - one in the northern (America/New_York maybe) and one in the southern hemisphere (Sydney is fine).
  5. Add a test that returns the same object during a non-ambiguous time in the northern hemisphere.
  6. Add a test that this returns the same object when handed a date already in UTC.

To summarize the changes to be made before this PR can be merged (and keep in mind any of the ones you don't do I can finish up):

  • Remove the .cache files.
  • Add a docstring.
  • Clean up the style of the tests
  • Add the additional tests detailed above

# Before Python 3.6, dt.fold won't exist if fold is 0.
self.assertEqual(getattr(dt, 'fold', 0), 0)

class imaginaryDateTest(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to do unittest style tests, the classes use CapWords, not camelCase, so this should be ImaginaryDateTest (the methods - the test names themselves - are fine as camelCase).

timezone = tz.gettz('Australia/Canberra')
dt = datetime(2018, 10, 7, 2, 30, tzinfo=timezone)
dt = tz.resolve_imaginary(dt)
self.assertEqual(dt,datetime(2018, 10, 7, 3, 30, tzinfo=timezone))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a space between the comma and datetime here. I would also probably not reassign dt here, but that's a minor thing.


class imaginaryDateTest(unittest.TestCase):
def testCanberraForward(self):
timezone = tz.gettz('Australia/Canberra')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timezone is actually already the name of a class in datetime in Python 3.3. I'd rather not shadow that variable, even though it causes no problems in this case. Probably call it tzi or something like CANBERRA.

timezone = tz.gettz('Australia/Sydney')
dt = datetime(2018, 4, 1, 3, 30, tzinfo=timezone)
dtnew = tz.resolve_imaginary(dt)
self.assertEqual(dt,dtnew)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like the guarantee here to be even stronger than assertEqual - this should in fact return the exact same object, so this should be changed to self.assertIs.

def __exit__(*args, **kwargs):
pass

def resolve_imaginary(dt):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a public function, it needs a docstring, explaining what it does, etc. See enfold, datetime_exists and datetime_ambiguous as examples.

timezone = tz.gettz('Africa/Monrovia')
dt = datetime(1972, 1, 7, hour = 0, minute = 30, second = 0, tzinfo=timezone)
dt = tz.resolve_imaginary(dt)
self.assertEqual(dt,datetime(1972, 1, 7, hour = 1, minute = 14, second = 30, tzinfo=timezone))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the failing test. I believe the reason it's failing is that tz.tzfile has the wrong behavior and is rounding time zones down to the nearest minute. Before Python 3.6, this was necessary because Python did not support non-integer number of minute offsets, but that is changed now. I'll make a PR that fixes this issue and that will allow this test to pass.

Another style note about this function - PEP8 recommends no space between keywords and arguments in functions. As a demonstration, here is how I would write this same function, taking into account the other stylistic notes from above:

def testMonroviaForward(self):
    tzi = tz.gettz('Africa/Monrovia')
    dt = datetime(1972, 1, 7, hour=0, minute=30, second=0, tzinfo=tzi)
    
    dt_act = tz.resolve_imaginary(dt)
    dt_exp = datetime(1972, 1, 7, hour=1, minute=14, second=30, tzinfo=tzi)
    self.assertEqual(dt, dt_exp)

dt = tz.resolve_imaginary(dt)
self.assertEqual(dt,datetime(2018, 10, 7, 3, 30, tzinfo=timezone))

def testSydneyBack(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize this originally, but datetime(2018, 4, 1, 3, 30) is very close to, but not actually an ambiguous time. It might be best to use a more obviously unambiguous time like datetime(2018, 6, 2, 12, 0).

Also maybe rename this to be like testSydneyExisting and/or add a comment like # Tests that resolve_imaginary has no effect on normal datetimes.

@pganssle
Copy link
Member

@Cheukting No matter what you end up doing, can you please add yourself to the AUTHORS.md file? Even if you make no other changes, your work on this so far deserves recognition.

@pganssle
Copy link
Member

pganssle commented Jan 3, 2018

Consolidated into #607.

@pganssle pganssle closed this Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants