<commit_before>import ROOT
import root_numpy as rnp
from root_numpy.testdata import get_file
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
from nose.tools import (raises, assert_raises, assert_true,
                        assert_equal, assert_almost_equal)
import warnings
from . import load, RNG, temp

try:
    from collections import OrderedDict
except ImportError:  # pragma: no cover
    from root_numpy.extern.ordereddict import OrderedDict


def test_testdata():
    assert_raises(ValueError, get_file, 'file_does_not_exist.root')


def check_single(single, n=100, offset=1):
    assert_equal(
        single.dtype,
        [('n_int', '<i4'), ('f_float', '<f4'), ('d_double', '<f8')])
    assert_equal(len(single), n)
    for i in range(len(single)):
        offset = (i // 100) + 1
        assert_equal(single[i][0], i % 100 + offset)
        assert_almost_equal(single[i][1], i % 100 * 2.0 + offset)
        assert_almost_equal(single[i][2], i % 100 * 3.0 + offset)


def test_list_trees():
    # TTree
    trees = rnp.list_trees(load('vary1.root'))
    assert_equal(trees, ['tree'])
    # TNtuple
    trees = rnp.list_trees(load('ntuple.root'))
    assert_equal(trees, ['ntuple'])
    # Multiple key cycles of the same tree
    with temp() as rfile:
        tree = ROOT.TTree("tree", "tree")
        rfile.Write()
        assert_equal(len(rnp.list_trees(rfile.GetName())), 1)
        rfile.Write()
        assert_equal(len(rnp.list_trees(rfile.GetName())), 1)


def test_list_branches():
    branches = rnp.list_branches(load('single1.root'))
    assert_equal(branches, ['n_int', 'f_float', 'd_double'])


def test_list_directories():<commit_msg>list_trees: test with subdirectory<commit_after>import ROOT
import root_numpy as rnp
from root_numpy.testdata import get_file
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
from nose.tools import (raises, assert_raises, assert_true,
                        assert_equal, assert_almost_equal)
import warnings
from . import load, RNG, temp

try:
    from collections import OrderedDict
except ImportError:  # pragma: no cover
    from root_numpy.extern.ordereddict import OrderedDict


def test_testdata():
    assert_raises(ValueError, get_file, 'file_does_not_exist.root')


def check_single(single, n=100, offset=1):
    assert_equal(
        single.dtype,
        [('n_int', '<i4'), ('f_float', '<f4'), ('d_double', '<f8')])
    assert_equal(len(single), n)
    for i in range(len(single)):
        offset = (i // 100) + 1
        assert_equal(single[i][0], i % 100 + offset)
        assert_almost_equal(single[i][1], i % 100 * 2.0 + offset)
        assert_almost_equal(single[i][2], i % 100 * 3.0 + offset)


def test_list_trees():
    # TTree
    trees = rnp.list_trees(load('vary1.root'))
    assert_equal(trees, ['tree'])
    # TNtuple
    trees = rnp.list_trees(load('ntuple.root'))
    assert_equal(trees, ['ntuple'])
    # Multiple key cycles of the same tree
    with temp() as rfile:
        tree = ROOT.TTree('tree', 'tree')
        rfile.Write()
        assert_equal(len(rnp.list_trees(rfile.GetName())), 1)
        rfile.Write()
        assert_equal(len(rnp.list_trees(rfile.GetName())), 1)
        rdir = rfile.mkdir('dir')
        rdir.cd()
        tree = ROOT.TTree('tree', 'tree')
        rfile.Write()
        assert_equal(set(rnp.list_trees(rfile.GetName())),
                     set(['tree', 'dir/tree']))


def test_list_branches():
    branches = rnp.list_branches(load('single1.root'))
    assert_equal(branches, ['n_int', 'f_float', 'd_double'])


def test_list_directories():
{'fraction_non_alphanumeric': 0.13459429824561403, 'fraction_numerical': 0.01699561403508772, 'mean_word_length': 3.504938271604938, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2736138', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1227, 'n_words': 274}