import unittest
from unittest import mock
from wqflask.marker_regression.run_mapping import get_genofile_samplelist


class AttributeSetter:
	def __init__(self,obj):
		for k,v in obj.items():
			setattr(self,k,v)


class MockDataSetGroup(AttributeSetter):
	
	def get_genofiles(self):
		return [{"location":"~/genofiles/g1_file","sample_list":["S1","S2","S3","S4"]}]
class TestRunMapping(unittest.TestCase):
	def setUp(self):
		self.group=MockDataSetGroup({"genofile":"~/genofiles/g1_file"})
		self.dataset=AttributeSetter({"group":self.group})

	def tearDown(self):
		self.dataset=AttributeSetter({"group":{"location":"~/genofiles/g1_file"}})


	def test_get_genofile_samplelist(self):
		#location true and sample list true

		results_1=get_genofile_samplelist(self.dataset)
		self.assertEqual(results_1,["S1","S2","S3","S4"])
		#return empty array
		self.group.genofile="~/genofiles/g2_file"
		result_2=get_genofile_samplelist(self.dataset)
		self.assertEqual(result_2,[])




@@ -109,17 +109,81 @@
 plelist%0A
+from wqflask.marker_regression.run_mapping import geno_db_exists
 %0A
-
 %0Aclass A
@@ -545,16 +545,30 @@
 g1_file%22
+,%22name%22:%22GP1_%22
 %7D)%0A%09%09sel
@@ -1005,32 +1005,32 @@
 t(self.dataset)%0A
-
 %09%09self.assertEqu
@@ -1046,10 +1046,504 @@
 _2,%5B%5D)%0A%0A
+%09@mock.patch(%22wqflask.marker_regression.run_mapping.data_set%22)%0A%09def test_geno_db_exists(self,mock_data_set):%0A%09%09# mock_data_set.create_dataset_side_effect=None%0A%09%09mock_data_set.create_dataset.side_effect=%5BAttributeSetter(%7B%7D),Exception()%5D%0A%09%09results_no_error=geno_db_exists(self.dataset)%0A%09%09results_with_error=geno_db_exists(self.dataset)%0A%0A%09%09self.assertEqual(mock_data_set.create_dataset.call_count,2)%0A%09%09self.assertEqual(results_with_error,%22False%22)%0A%09%09self.assertEqual(results_no_error,%22True%22)%0A%0A%0A%0A%0A%0A%0A
 %0A%0A

add tests for geno_db_exists in marker_regression/run_mapping.py