import unittest

from github2.issues import Issue
from github2.client import Github


class ReprTests(unittest.TestCase):
    """__repr__ must return strings, not unicode objects."""

    def test_issue(self):
        """Issues can have non-ASCII characters in the title."""
        i = Issue(title=u'abcdé')
        self.assertEqual(str, type(repr(i)))


class RateLimits(unittest.TestCase):
    """
    How should we handle actual API calls such that tests can run?
    Perhaps the library should support a ~/.python_github2.conf from which to
    get the auth?
    """
    def test_delays(self):
        import datetime
        USERNAME = ''
        API_KEY = ''
        client = Github(username=USERNAME, api_token=API_KEY,
            requests_per_second=.5)
        client.users.show('defunkt')
        start = datetime.datetime.now()
        client.users.show('mojombo')
        end = datetime.datetime.now()
        self.assertGreaterEqual((end - start).total_seconds(), 2.0,
            "Expected .5 reqs per second to require a 2 second delay between "
            "calls.")

import unittest

from github2.issues import Issue
from github2.client import Github


class ReprTests(unittest.TestCase):
    """__repr__ must return strings, not unicode objects."""

    def test_issue(self):
        """Issues can have non-ASCII characters in the title."""
        i = Issue(title=u'abcdé')
        self.assertEqual(str, type(repr(i)))


class RateLimits(unittest.TestCase):
    """
    How should we handle actual API calls such that tests can run?
    Perhaps the library should support a ~/.python_github2.conf from which to
    get the auth?
    """
    def test_delays(self):
        import datetime
        USERNAME = ''
        API_KEY = ''
        client = Github(username=USERNAME, api_token=API_KEY,
            requests_per_second=.5)
        client.users.show('defunkt')
        start = datetime.datetime.now()
        client.users.show('mojombo')
        end = datetime.datetime.now()

        delta = end - start
        delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds

        self.assertTrue(delta_seconds >= 2,
            "Expected .5 reqs per second to require a 2 second delay between "
            "calls.")

Allow tests to be run with Python <2.6.
Allow tests to be run with Python <2.6.

  import unittest
  
  from github2.issues import Issue
  from github2.client import Github
  
  
  class ReprTests(unittest.TestCase):
      """__repr__ must return strings, not unicode objects."""
  
      def test_issue(self):
          """Issues can have non-ASCII characters in the title."""
          i = Issue(title=u'abcdé')
          self.assertEqual(str, type(repr(i)))
  
  
  class RateLimits(unittest.TestCase):
      """
      How should we handle actual API calls such that tests can run?
      Perhaps the library should support a ~/.python_github2.conf from which to
      get the auth?
      """
      def test_delays(self):
          import datetime
          USERNAME = ''
          API_KEY = ''
          client = Github(username=USERNAME, api_token=API_KEY,
              requests_per_second=.5)
          client.users.show('defunkt')
          start = datetime.datetime.now()
          client.users.show('mojombo')
          end = datetime.datetime.now()
-         self.assertGreaterEqual((end - start).total_seconds(), 2.0,
+ 
+         delta = end - start
+         delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds
+ 
+         self.assertTrue(delta_seconds >= 2,
              "Expected .5 reqs per second to require a 2 second delay between "
              "calls.")
  
Allow tests to be run with Python <2.6.
## Code Before:
import unittest

from github2.issues import Issue
from github2.client import Github


class ReprTests(unittest.TestCase):
    """__repr__ must return strings, not unicode objects."""

    def test_issue(self):
        """Issues can have non-ASCII characters in the title."""
        i = Issue(title=u'abcdé')
        self.assertEqual(str, type(repr(i)))


class RateLimits(unittest.TestCase):
    """
    How should we handle actual API calls such that tests can run?
    Perhaps the library should support a ~/.python_github2.conf from which to
    get the auth?
    """
    def test_delays(self):
        import datetime
        USERNAME = ''
        API_KEY = ''
        client = Github(username=USERNAME, api_token=API_KEY,
            requests_per_second=.5)
        client.users.show('defunkt')
        start = datetime.datetime.now()
        client.users.show('mojombo')
        end = datetime.datetime.now()
        self.assertGreaterEqual((end - start).total_seconds(), 2.0,
            "Expected .5 reqs per second to require a 2 second delay between "
            "calls.")

## Instruction:
Allow tests to be run with Python <2.6.
## Code After:
import unittest

from github2.issues import Issue
from github2.client import Github


class ReprTests(unittest.TestCase):
    """__repr__ must return strings, not unicode objects."""

    def test_issue(self):
        """Issues can have non-ASCII characters in the title."""
        i = Issue(title=u'abcdé')
        self.assertEqual(str, type(repr(i)))


class RateLimits(unittest.TestCase):
    """
    How should we handle actual API calls such that tests can run?
    Perhaps the library should support a ~/.python_github2.conf from which to
    get the auth?
    """
    def test_delays(self):
        import datetime
        USERNAME = ''
        API_KEY = ''
        client = Github(username=USERNAME, api_token=API_KEY,
            requests_per_second=.5)
        client.users.show('defunkt')
        start = datetime.datetime.now()
        client.users.show('mojombo')
        end = datetime.datetime.now()

        delta = end - start
        delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds

        self.assertTrue(delta_seconds >= 2,
            "Expected .5 reqs per second to require a 2 second delay between "
            "calls.")
