from gym import error, envs
from gym.envs import registration
from gym.envs.classic_control import cartpole

def test_make():
    env = envs.make('CartPole-v0')
    assert env.spec.id == 'CartPole-v0'
    assert isinstance(env, cartpole.CartPoleEnv)

def test_spec():
    spec = envs.spec('CartPole-v0')
    assert spec.id == 'CartPole-v0'

def test_missing_lookup():
    registry = registration.EnvRegistry()
    registry.register(id='Test-v0', entry_point=None)
    registry.register(id='Test-v15', entry_point=None)
    registry.register(id='Test-v9', entry_point=None)
    registry.register(id='Other-v100', entry_point=None)
    try:
        registry.spec('Test-v1')
    except error.UnregisteredEnv:
        pass
    else:
        assert False

def test_malformed_lookup():
    registry = registration.EnvRegistry()
    try:
        registry.spec(u'“Breakout-v0”')
    except error.Error as e:
        assert 'malformed environment ID' in e.message, 'Unexpected message: {}'.format(e)
    else:
        assert False

from gym import error, envs
from gym.envs import registration
from gym.envs.classic_control import cartpole

def test_make():
    env = envs.make('CartPole-v0')
    assert env.spec.id == 'CartPole-v0'
    assert isinstance(env, cartpole.CartPoleEnv)

def test_spec():
    spec = envs.spec('CartPole-v0')
    assert spec.id == 'CartPole-v0'

def test_missing_lookup():
    registry = registration.EnvRegistry()
    registry.register(id='Test-v0', entry_point=None)
    registry.register(id='Test-v15', entry_point=None)
    registry.register(id='Test-v9', entry_point=None)
    registry.register(id='Other-v100', entry_point=None)
    try:
        registry.spec('Test-v1')
    except error.UnregisteredEnv:
        pass
    else:
        assert False

def test_malformed_lookup():
    registry = registration.EnvRegistry()
    try:
        registry.spec(u'“Breakout-v0”')
    except error.Error as e:
        assert 'malformed environment ID' in '{}'.format(e), 'Unexpected message: {}'.format(e)
    else:
        assert False

Fix exception message formatting in Python3
Fix exception message formatting in Python3

  from gym import error, envs
  from gym.envs import registration
  from gym.envs.classic_control import cartpole
  
  def test_make():
      env = envs.make('CartPole-v0')
      assert env.spec.id == 'CartPole-v0'
      assert isinstance(env, cartpole.CartPoleEnv)
  
  def test_spec():
      spec = envs.spec('CartPole-v0')
      assert spec.id == 'CartPole-v0'
  
  def test_missing_lookup():
      registry = registration.EnvRegistry()
      registry.register(id='Test-v0', entry_point=None)
      registry.register(id='Test-v15', entry_point=None)
      registry.register(id='Test-v9', entry_point=None)
      registry.register(id='Other-v100', entry_point=None)
      try:
          registry.spec('Test-v1')
      except error.UnregisteredEnv:
          pass
      else:
          assert False
  
  def test_malformed_lookup():
      registry = registration.EnvRegistry()
      try:
          registry.spec(u'“Breakout-v0”')
      except error.Error as e:
-         assert 'malformed environment ID' in e.message, 'Unexpected message: {}'.format(e)
+         assert 'malformed environment ID' in '{}'.format(e), 'Unexpected message: {}'.format(e)
      else:
          assert False
  
Fix exception message formatting in Python3
## Code Before:
from gym import error, envs
from gym.envs import registration
from gym.envs.classic_control import cartpole

def test_make():
    env = envs.make('CartPole-v0')
    assert env.spec.id == 'CartPole-v0'
    assert isinstance(env, cartpole.CartPoleEnv)

def test_spec():
    spec = envs.spec('CartPole-v0')
    assert spec.id == 'CartPole-v0'

def test_missing_lookup():
    registry = registration.EnvRegistry()
    registry.register(id='Test-v0', entry_point=None)
    registry.register(id='Test-v15', entry_point=None)
    registry.register(id='Test-v9', entry_point=None)
    registry.register(id='Other-v100', entry_point=None)
    try:
        registry.spec('Test-v1')
    except error.UnregisteredEnv:
        pass
    else:
        assert False

def test_malformed_lookup():
    registry = registration.EnvRegistry()
    try:
        registry.spec(u'“Breakout-v0”')
    except error.Error as e:
        assert 'malformed environment ID' in e.message, 'Unexpected message: {}'.format(e)
    else:
        assert False

## Instruction:
Fix exception message formatting in Python3
## Code After:
from gym import error, envs
from gym.envs import registration
from gym.envs.classic_control import cartpole

def test_make():
    env = envs.make('CartPole-v0')
    assert env.spec.id == 'CartPole-v0'
    assert isinstance(env, cartpole.CartPoleEnv)

def test_spec():
    spec = envs.spec('CartPole-v0')
    assert spec.id == 'CartPole-v0'

def test_missing_lookup():
    registry = registration.EnvRegistry()
    registry.register(id='Test-v0', entry_point=None)
    registry.register(id='Test-v15', entry_point=None)
    registry.register(id='Test-v9', entry_point=None)
    registry.register(id='Other-v100', entry_point=None)
    try:
        registry.spec('Test-v1')
    except error.UnregisteredEnv:
        pass
    else:
        assert False

def test_malformed_lookup():
    registry = registration.EnvRegistry()
    try:
        registry.spec(u'“Breakout-v0”')
    except error.Error as e:
        assert 'malformed environment ID' in '{}'.format(e), 'Unexpected message: {}'.format(e)
    else:
        assert False
