def test_anonymous_name(): from rosgraph.names import anonymous_name, is_legal_name val = anonymous_name('foo') assert 'foo' in val assert 'foo' != val assert val != anonymous_name('foo') assert not '/' in val assert is_legal_name(val)
def _anonymous_name(self, name): try: from rosgraph.names import anonymous_name return anonymous_name(name) except ImportError: import random, socket, sys, warnings warnings.warn("Could not import the 'rosgraph' package; " "resorting to fallback behaviour.") # Behaviour copied from rosgraph.names name = "{}_{}_{}_{}".format(name, socket.gethostname(), os.getpid(), random.randint(0, sys.maxsize)) return name.replace('.', '_').replace('-', '_').replace(':', '_')