<commit_before>from __future__ import absolute_import
from __future__ import unicode_literals

import json
import pickle
import unittest

import datpy

try:
  import pandas as pd
except:
  pd = False

class DatTest(unittest.TestCase):

  @classmethod
  def setUpClass(cls):
    cls.dat = datpy.Dat('.')
    cls.dat.init()

  @classmethod
  def tearDownClass(cls):
    cls.dat.destroy()

class IsolatedTest(DatTest):

  def test_insert_with_dataset(self):
    dataset = self.dat.dataset('contracts')
    version = dataset.import_file("examples/contracts.csv")
    self.assertEqual(len(version), 64)
    output = dataset.export()
    self.assertEqual(len(output), 770)
    self.assertTrue('amtSpent' in output[0])

    status = self.dat.status()
    self.assertEqual(len(status['datasets']), 2)
    self.assertEqual(status['files'], 1)
    #self.assertEqual(status['rows'], 770)

    dat = datpy.clone('.', 'test')
    self.assertEqual(status, dat.status())
    dat.destroy()

    datasets = self.dat.datasets()
    self.assertEqual(len(datasets), 2)
    self.assertTrue('files' in datasets)
    self.assertTrue('contracts' in datasets)


class IOTests(DatTest):

  def test_insert_with_dataset(self):
    dataset = self.dat.dataset('contracts')
    version = dataset.import_file("examples/contracts.csv")
    self.assertEqual(len(version), 64)
    output = dataset.export()
    self.assertEqual(len(output), 770)

  def test_insert_with_bad_path_fails(self):
    dataset = self.dat.dataset('contracts2')
    with self.assertRaises(Exception):
        dataset.import_file("not-a-file.csv")

  def test_write_file(self):
    version = self.dat.write_file("examples/blob.txt")
    self.assertEqual(len(version), 64)
    output = self.dat.read("blob.txt")
    self.assertEqual(output, "hello world\n")

  def test_write_blob_from_python(self):
    version = self.dat.write("hello.txt", data="hello world")
    self.assertEqual(len(version), 64)
    self.assertEqual(self.dat.read("hello.txt"), "hello world")

  def test_write_dict_from_python(self):
    my_python_object = {
      "hello": "world",<commit_msg>fix tests<commit_after>from __future__ import absolute_import
from __future__ import unicode_literals

import json
import pickle
import unittest

import datpy

try:
  import pandas as pd
except:
  pd = False

class DatTest(unittest.TestCase):

  @classmethod
  def setUpClass(cls):
    cls.dat = datpy.Dat('.')
    cls.dat.init()

  @classmethod
  def tearDownClass(cls):
    cls.dat.destroy()

class IsolatedTest(DatTest):

  def test_insert_with_dataset(self):
    dataset = self.dat.dataset('contracts')
    version = dataset.import_file("examples/contracts.csv")
    self.assertEqual(len(version), 64)
    output = dataset.export()
    self.assertEqual(len(output), 770)
    self.assertTrue('amtSpent' in output[0])

    status = self.dat.status()
    self.assertEqual(len(status['datasets']), 1)
    self.assertEqual(status['files'], 1)
    #self.assertEqual(status['rows'], 770)

    dat = datpy.clone('.', 'test')
    self.assertEqual(status, dat.status())
    dat.destroy()

    datasets = self.dat.datasets()
    self.assertEqual(len(datasets), 1)
    self.assertTrue('contracts' in datasets)


class IOTests(DatTest):

  def test_insert_with_dataset(self):
    dataset = self.dat.dataset('contracts')
    version = dataset.import_file("examples/contracts.csv")
    self.assertEqual(len(version), 64)
    output = dataset.export()
    self.assertEqual(len(output), 770)

  def test_insert_with_bad_path_fails(self):
    dataset = self.dat.dataset('contracts2')
    with self.assertRaises(Exception):
        dataset.import_file("not-a-file.csv")

  def test_write_file(self):
    version = self.dat.write_file("examples/blob.txt")
    self.assertEqual(len(version), 64)
    output = self.dat.read("blob.txt")
    self.assertEqual(output, "hello world\n")

  def test_write_blob_from_python(self):
    version = self.dat.write("hello.txt", data="hello world")
    self.assertEqual(len(version), 64)
    self.assertEqual(self.dat.read("hello.txt"), "hello world")

  def test_write_dict_from_python(self):
    my_python_object = {
      "hello": "world",
{'fraction_non_alphanumeric': 0.13702903767698585, 'fraction_numerical': 0.010559155267578594, 'mean_word_length': 4.223057644110276, 'pattern_counts': {'":': 2, '<': 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': '1492061', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1343, 'n_words': 247}