Skip to content

Commit

Permalink
Make RDFValues more readable; use latest Travis OSX image.
Browse files Browse the repository at this point in the history
  • Loading branch information
ogarod committed Feb 8, 2018
1 parent fa763df commit 6278dce
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ matrix:
# OSX builds
- os: osx
# psutil fails to install on the default beta-xcode6.1
osx_image: xcode6.4
language: generic
osx_image: xcode9.2
python: 2.7
sudo: required
env:
Expand Down
15 changes: 14 additions & 1 deletion grr/lib/rdfvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ def __bool__(self):
def __nonzero__(self):
return bool(self._value)

def __str__(self): # pylint: disable=super-on-old-class
"""Ignores the __repr__ override below to avoid indefinite recursion."""
return super(RDFValue, self).__repr__()

def __repr__(self):
content = utils.SmartStr(self)
if len(content) > 100:
content = content[:100] + "..."

# Note %r, which prevents nasty nonascii characters from being printed,
# including dangerous terminal escape sequences.
return "<%s(%r)>" % (self.__class__.__name__, content)


class RDFBytes(RDFValue):
"""An attribute which holds bytes."""
Expand Down Expand Up @@ -969,7 +982,7 @@ def RelativeName(self, volume):
return None

def __repr__(self):
return "<%s age=%s>" % (str(self), self.age)
return "<%s age=%s>" % (self, self.age)


class Subject(RDFURN):
Expand Down
47 changes: 47 additions & 0 deletions grr/lib/rdfvalue_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# -*- mode: python; encoding: utf-8 -*-
"""Tests for utility classes."""


import unittest
from grr.lib import flags
from grr.lib import rdfvalue
from grr.test_lib import test_lib

long_string = (
"迎欢迎\n"
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi luctus "
"ex sed dictum volutpat. Integer maximus, mauris at tincidunt iaculis, "
"felis magna scelerisque ex, in scelerisque est odio non nunc. "
"Suspendisse et lobortis augue. Donec faucibus tempor massa, sed dapibus"
" erat iaculis ut. Vestibulum eu elementum nulla. Nullam scelerisque "
"hendrerit lorem. Integer vitae semper metus. Suspendisse accumsan "
"dictum felis. Etiam viverra, felis sed ullamcorper vehicula, libero "
"nisl tempus dui, a porta lacus erat et erat. Morbi mattis elementum "
"efficitur. Pellentesque aliquam placerat mauris non accumsan.")


class RDFValueTest(unittest.TestCase):
"""RDFValue tests."""

def testStr(self):
"""Test RDFValue.__str__."""
self.assertEqual(str(rdfvalue.RDFBool(True)), "1")
self.assertEqual(str(rdfvalue.RDFString(long_string)), long_string)

def testRepr(self):
"""Test RDFValue.__repr__."""
self.assertEqual(repr(rdfvalue.RDFBool(True)), "<RDFBool('1')>")
self.assertEqual(
repr(rdfvalue.RDFString(long_string)),
"<RDFString('\\xe8\\xbf\\x8e\\xe6\\xac\\xa2\\xe8\\xbf\\x8e\\nLorem "
"ipsum dolor sit amet, consectetur adipiscing elit. Morbi luctus ex "
"sed dictum volutp...')>")


def main(argv):
test_lib.main(argv)


if __name__ == "__main__":
flags.StartMain(main)
1 change: 1 addition & 0 deletions grr/lib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from grr.lib import lexer_test
from grr.lib import objectfilter_test
from grr.lib import parsers_test
from grr.lib import rdfvalue_test
from grr.lib import repacking_test
from grr.lib import stats_test
from grr.lib import type_info_test
Expand Down
2 changes: 1 addition & 1 deletion grr/lib/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from grr.lib import utils
from grr.test_lib import test_lib

# Test method names dont conform with Google style
# Test method names don't conform with Google style
# pylint: disable=g-bad-name


Expand Down
2 changes: 1 addition & 1 deletion travis/deploy_to_gcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function delete_gcs_keys() {
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
shred -u travis/travis_uploader_service_account.json
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
srm -sz travis/travis_uploader_service_account.json
rm -P travis/travis_uploader_service_account.json
fi
}

Expand Down

0 comments on commit 6278dce

Please sign in to comment.