<commit_before>import unittest, os
import pandas as pd
import pandas.util.testing as pdt
import numpy as np
from subprocess import CalledProcessError
#from .. import bbsr_R
from .. import bbsr_python

my_dir = os.path.dirname(__file__)

class TestBBSRrunnerPython(unittest.TestCase):

    def setUp(self):
        self.brd = bbsr_python.BBSR_runner()
        #self.brd = bbsr_R.BBSR_driver()
        #self.brd.target_directory = os.path.join(my_dir, "artifacts")

        #if not os.path.exists(self.brd.target_directory):
        #    os.makedirs(self.brd.target_directory)

    def set_all_zero_priors(self):
        self.priors =  pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2'])

    def set_all_zero_clr(self):
        self.clr = pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2'])

    def assert_matrix_is_square(self, size, matrix):
        self.assertEqual(matrix.shape, (size, size))

    def test_two_genes(self):
        self.set_all_zero_priors()
        self.set_all_zero_clr()
        self.X = pd.DataFrame([0, 0], index = ['gene1', 'gene2'], columns = ['ss'])
        self.Y = pd.DataFrame([0, 0], index = ['gene1', 'gene2'], columns = ['ss'])

        (betas, resc) = self.brd.run(self.X, self.Y, self.clr, self.priors)
        self.assert_matrix_is_square(2, betas)
        self.assert_matrix_is_square(2, resc)
        pdt.assert_frame_equal(betas, pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2']).astype(float))
        pdt.assert_frame_equal(resc, pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2']).astype(float))

    def test_fails_with_one_gene(self):
        self.set_all_zero_priors()
        self.set_all_zero_clr()
        self.X = pd.DataFrame([0], index = ['gene1'], columns = ['ss'])
        self.Y = pd.DataFrame([0], index = ['gene1'], columns = ['ss'])
        self.assertRaises(CalledProcessError, self.brd.run, self.X, self.Y, self.clr, self.priors)

    def test_two_genes_nonzero(self):
        self.set_all_zero_priors()
        self.set_all_zero_clr()
        self.X = pd.DataFrame([1, 2], index = ['gene1', 'gene2'], columns = ['ss'])
        self.Y = pd.DataFrame([1, 2], index = ['gene1', 'gene2'], columns = ['ss'])
        (betas, resc) = self.brd.run(self.X, self.Y, self.clr, self.priors)
        self.assert_matrix_is_square(2, betas)
        self.assert_matrix_is_square(2, resc)<commit_msg>commented out test for one gene failing, no called process error in python<commit_after>import unittest, os
import pandas as pd
import pandas.util.testing as pdt
import numpy as np
from subprocess import CalledProcessError
#from .. import bbsr_R
from .. import bbsr_python

my_dir = os.path.dirname(__file__)

class TestBBSRrunnerPython(unittest.TestCase):

    def setUp(self):
        self.brd = bbsr_python.BBSR_runner()
        #self.brd = bbsr_R.BBSR_driver()
        #self.brd.target_directory = os.path.join(my_dir, "artifacts")

        #if not os.path.exists(self.brd.target_directory):
        #    os.makedirs(self.brd.target_directory)

    def set_all_zero_priors(self):
        self.priors =  pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2'])

    def set_all_zero_clr(self):
        self.clr = pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2'])

    def assert_matrix_is_square(self, size, matrix):
        self.assertEqual(matrix.shape, (size, size))

    def test_two_genes(self):
        self.set_all_zero_priors()
        self.set_all_zero_clr()
        self.X = pd.DataFrame([0, 0], index = ['gene1', 'gene2'], columns = ['ss'])
        self.Y = pd.DataFrame([0, 0], index = ['gene1', 'gene2'], columns = ['ss'])

        (betas, resc) = self.brd.run(self.X, self.Y, self.clr, self.priors)
        self.assert_matrix_is_square(2, betas)
        self.assert_matrix_is_square(2, resc)
        pdt.assert_frame_equal(betas, pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2']).astype(float))
        pdt.assert_frame_equal(resc, pd.DataFrame([[0, 0],[0, 0]], index = ['gene1', 'gene2'], columns = ['gene1', 'gene2']).astype(float))

    '''
    def test_fails_with_one_gene(self):
        self.set_all_zero_priors()
        self.set_all_zero_clr()
        self.X = pd.DataFrame([0], index = ['gene1'], columns = ['ss'])
        self.Y = pd.DataFrame([0], index = ['gene1'], columns = ['ss'])
        self.assertRaises(CalledProcessError, self.brd.run, self.X, self.Y, self.clr, self.priors)
    '''
    def test_two_genes_nonzero(self):
        self.set_all_zero_priors()
        self.set_all_zero_clr()
        self.X = pd.DataFrame([1, 2], index = ['gene1', 'gene2'], columns = ['ss'])
        self.Y = pd.DataFrame([1, 2], index = ['gene1', 'gene2'], columns = ['ss'])
        (betas, resc) = self.brd.run(self.X, self.Y, self.clr, self.priors)
        self.assert_matrix_is_square(2, betas)
        self.assert_matrix_is_square(2, resc)
{'fraction_non_alphanumeric': 0.17259786476868327, 'fraction_numerical': 0.022143139580862, 'mean_word_length': 3.406794425087108, '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': '3611134', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1841, 'n_words': 361}