コード例 #1
0
ファイル: test_convert.py プロジェクト: RootForum/magrathea
    def test_21(self):
        """
        Test Case 21:
        Convert a non-bytes object into a string.

        Test is passed if the returned result is a string and equals the expected result.
        """
        test_string = u"[1, 2, 3]"
        test_bytes = [1, 2, 3]
        self.assertIsInstance(to_str(test_bytes), unicode)
        self.assertSequenceEqual(to_str(test_bytes), test_string)
コード例 #2
0
ファイル: test_convert.py プロジェクト: RootForum/magrathea
    def test_20(self):
        """
        Test Case 20:
        Convert False into a string.

        Test is passed if the returned result is a string and equals the expected result.
        """
        test_string = u"False"
        test_bytes = False
        self.assertIsInstance(to_str(test_bytes), unicode)
        self.assertSequenceEqual(to_str(test_bytes), test_string)
コード例 #3
0
ファイル: test_convert.py プロジェクト: RootForum/magrathea
    def test_18(self):
        """
        Test Case 18:
        Convert a byte array into a string.

        Test is passed if the returned result is a string and equals the expected result.
        """
        test_string = u"test"
        test_bytes = bytearray(b"test")
        self.assertIsInstance(to_str(test_bytes), unicode)
        self.assertSequenceEqual(to_str(test_bytes), test_string)
コード例 #4
0
ファイル: test_convert.py プロジェクト: RootForum/magrathea
    def test_16(self):
        """
        Test Case 16:
        Convert an empty byte sequence into a string.

        Test is passed if the returned result is a sting and equals the expected result.
        """
        test_string = u""
        test_bytes = b""
        self.assertIsInstance(to_str(test_bytes), unicode)
        self.assertSequenceEqual(to_str(test_bytes), test_string)
コード例 #5
0
ファイル: test_convert.py プロジェクト: RootForum/magrathea
    def test_12(self):
        """
        Test Case 12:
        Convert None into a string.

        Test is passed if the returned result is a string and equals the expected result.
        """
        test_string = ""
        test_bytes = None
        self.assertIsInstance(to_str(test_bytes), str)
        self.assertSequenceEqual(to_str(test_bytes), test_string)
コード例 #6
0
ファイル: test_convert.py プロジェクト: RootForum/magrathea
    def test_08(self):
        """
        Test Case 08:
        Convert a non-empty byte sequence into a string.

        Test is passed if the returned result is a string and equals the expected result.
        """
        test_string = "test"
        test_bytes = b"test"
        self.assertIsInstance(to_str(test_bytes), str)
        self.assertSequenceEqual(to_str(test_bytes), test_string)
コード例 #7
0
ファイル: version.py プロジェクト: RootForum/magrathea
def get_git_changeset(path=None):
    """
    Returns a numeric identifier of the latest `Git`_ changeset.

    Since the Git revision hash does not fulfil the requirements
    of `PEP 386`_, the UTC timestamp in YYYYMMDDHHMMSS format is used
    instead. This value is not guaranteed to be unique, however the
    likeliness of collisions is small enough to be acceptable for
    the purpose of building version numbers.

    :param str path: Path to the `Git`_ repository to detect the latest commit timestamp from.
                     If not indicated, the parent path of the magrathea package is used.
    :returns: a string of the format ``GIT-timestamp`` with timestamp being either a 14 digit
              integer, or the string "unknown" in cases where the changeset timestamp could not
              be detected.

    .. _PEP 386: http://www.python.org/dev/peps/pep-0386/
    .. _Git: http://git-scm.com/
    """
    if path is None:
        path = os.path.normpath(os.path.join(magrathea.__path__[0], ".."))

    # run `git show` in ControlBeast's root directory and grab its output from stdout
    git_show = subprocess.Popen(
        'git show --pretty=format:%ct --quiet HEAD',
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        shell=True,
        cwd=path,
        universal_newlines=True
    )
    try:
        timestamp = to_str(git_show.communicate()[0]).partition('\n')[0]
    except OSError:
        timestamp = None

    try:
        timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
    except (ValueError, TypeError):
        return 'GIT-unknown'

    return 'GIT-{0:>s}'.format(timestamp.strftime('%Y%m%d%H%M%S'))