<commit_before># Copyright 2017 The dm_control Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""Tests to check whether methods of `mujoco.Physics` are threadsafe."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# Internal dependencies.

from absl.testing import absltest

from dm_control.mujoco import engine
from dm_control.mujoco.testing import assets
from dm_control.mujoco.testing import decorators

MODEL = assets.get_contents('cartpole.xml')
NUM_STEPS = 10


class ThreadSafetyTest(absltest.TestCase):

  @decorators.run_threaded()
  def test_load_physics_from_string(self):
    engine.Physics.from_xml_string(MODEL)

  @decorators.run_threaded()
  def test_load_and_reload_physics_from_string(self):
    physics = engine.Physics.from_xml_string(MODEL)
    physics.reload_from_xml_string(MODEL)

  @decorators.run_threaded()
  def test_load_and_step_physics(self):
    physics = engine.Physics.from_xml_string(MODEL)
    for _ in xrange(NUM_STEPS):
      physics.step()

  @decorators.run_threaded()
  def test_load_and_step_multiple_physics_parallel(self):
    physics1 = engine.Physics.from_xml_string(MODEL)
    physics2 = engine.Physics.from_xml_string(MODEL)
    for _ in xrange(NUM_STEPS):
      physics1.step()
      physics2.step()
<commit_msg>Define xrange() for Python 3<commit_after># Copyright 2017 The dm_control Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""Tests to check whether methods of `mujoco.Physics` are threadsafe."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# Internal dependencies.

from absl.testing import absltest

from dm_control.mujoco import engine
from dm_control.mujoco.testing import assets
from dm_control.mujoco.testing import decorators

MODEL = assets.get_contents('cartpole.xml')
NUM_STEPS = 10

try:
  xrange          # Python 2
except NameError:
  xrange = range  # Python 3


class ThreadSafetyTest(absltest.TestCase):

  @decorators.run_threaded()
  def test_load_physics_from_string(self):
    engine.Physics.from_xml_string(MODEL)

  @decorators.run_threaded()
  def test_load_and_reload_physics_from_string(self):
    physics = engine.Physics.from_xml_string(MODEL)
    physics.reload_from_xml_string(MODEL)

  @decorators.run_threaded()
  def test_load_and_step_physics(self):
    physics = engine.Physics.from_xml_string(MODEL)
    for _ in xrange(NUM_STEPS):
      physics.step()

  @decorators.run_threaded()
  def test_load_and_step_multiple_physics_parallel(self):
    physics1 = engine.Physics.from_xml_string(MODEL)
    physics2 = engine.Physics.from_xml_string(MODEL)
    for _ in xrange(NUM_STEPS):
      physics1.step()
      physics2.step()

{'fraction_non_alphanumeric': 0.11292378281927097, 'fraction_numerical': 0.007902115727759368, 'mean_word_length': 5.046224961479199, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1871654', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1173, 'n_words': 334}