<commit_before>"""
    Unit tests for yaml.
"""

import os,tempfile
from nose import SkipTest

import networkx as nx

class TestYaml(object):
    @classmethod
    def setupClass(cls):
        global yaml
        try:
            import yaml
            # Because NetworkX uses a lazy import, this might work.
            # To really test it, we need to use it.
            yaml.__file__
        except ImportError:
            raise SkipTest('yaml not available.')

        self.build_graphs()

    def build_graphs(self):
        self.G = nx.Graph(name="test")
        e = [('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
        self.G.add_edges_from(e)
        self.G.add_node('g')    

        self.DG = nx.DiGraph(G)

        self.XG = nx.MultiGraph()
        self.XG.add_weighted_edges_from([(1,2,5),(1,2,5),(1,2,1),(3,3,42)])

    def assert_equal(self, G, data=False):
        (fd, fname) = tempfile.mkstemp()
        nx.write_yaml(G, fname)
        Gin = read_yaml(fname);

        assert_true( sorted(G.nodes())==sorted(Gin.nodes()) )
        assert_true( sorted(G.edges(data=data))==sorted(Gin.edges(data=data)) )

        os.close(fd)
        os.unlink(fname)
   
    def testUndirected(self):
        self.assert_equal(self.G, False)

    def testDirected(self):
        self.assert_equal(self.DG, False)

    def testMultiGraph(self):
        self.assert_equal(self.MG, True)

<commit_msg>Fix yaml nosetest for case when yaml is installed<commit_after>"""
    Unit tests for yaml.
"""

import os,tempfile
from nose import SkipTest
from nose.tools import assert_true

import networkx as nx

class TestYaml(object):
    @classmethod
    def setupClass(cls):
        global yaml
        try:
            import yaml
            # Because NetworkX uses a lazy import, this might work.
            # To really test it, we need to use it.
            yaml.__file__
        except ImportError:
            raise SkipTest('yaml not available.')

    def setUp(self):
        self.build_graphs()

    def build_graphs(self):
        self.G = nx.Graph(name="test")
        e = [('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
        self.G.add_edges_from(e)
        self.G.add_node('g')    

        self.DG = nx.DiGraph(self.G)

        self.MG = nx.MultiGraph()
        self.MG.add_weighted_edges_from([(1,2,5),(1,2,5),(1,2,1),(3,3,42)])

    def assert_equal(self, G, data=False):
        (fd, fname) = tempfile.mkstemp()
        nx.write_yaml(G, fname)
        Gin = nx.read_yaml(fname);

        assert_true( sorted(G.nodes())==sorted(Gin.nodes()) )
        assert_true( sorted(G.edges(data=data))==sorted(Gin.edges(data=data)) )

        os.close(fd)
        os.unlink(fname)
   
    def testUndirected(self):
        self.assert_equal(self.G, False)

    def testDirected(self):
        self.assert_equal(self.DG, False)

    def testMultiGraph(self):
        self.assert_equal(self.MG, True)


{'fraction_non_alphanumeric': 0.1534788540245566, 'fraction_numerical': 0.008867667121418827, 'mean_word_length': 2.4264018691588785, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2748851', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1003, 'n_words': 200}