def get_test_doclist(doctype, name=None): """get test doclist, collection of doclists""" import os from frappe import conf from frappe.modules.utils import peval_doclist from frappe.modules import scrub doctype = scrub(doctype) doctype_path = os.path.join( os.path.dirname(os.path.abspath(conf.__file__)), conf.test_data_path, doctype) if name: with open(os.path.join(doctype_path, scrub(name) + ".json"), 'r') as txtfile: doclist = peval_doclist(txtfile.read()) return doclist else: all_doclists = [] for fname in filter(lambda n: n.endswith(".json"), os.listdir(doctype_path)): with open(os.path.join(doctype_path, scrub(fname)), 'r') as txtfile: all_doclists.append(peval_doclist(txtfile.read())) return all_doclists
def read_doclist_from_file(path): doclist = None if os.path.exists(path): from frappe.modules.utils import peval_doclist with open(path, 'r') as f: doclist = peval_doclist(f.read()) else: raise Exception, '%s missing' % path return doclist
def get_test_doclist(doctype, name=None): """get test doclist, collection of doclists""" import os, frappe from frappe import conf from frappe.modules.utils import peval_doclist from frappe.modules import scrub doctype = scrub(doctype) doctype_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)), conf.test_data_path, doctype) if name: with open(os.path.join(doctype_path, scrub(name) + ".json"), 'r') as txtfile: doclist = peval_doclist(txtfile.read()) return doclist else: all_doclists = [] for fname in filter(lambda n: n.endswith(".json"), os.listdir(doctype_path)): with open(os.path.join(doctype_path, scrub(fname)), 'r') as txtfile: all_doclists.append(peval_doclist(txtfile.read())) return all_doclists
def _run_test(path, filename, verbose, test_suite=None, run=True): import os, imp from frappe.modules.utils import peval_doclist if not test_suite: test_suite = unittest.TestSuite() if os.path.basename(os.path.dirname(path))=="doctype": txt_file = os.path.join(path, filename[5:].replace(".py", ".txt")) with open(txt_file, 'r') as f: doctype_doclist = peval_doclist(f.read()) doctype = doctype_doclist[0]["name"] make_test_records(doctype, verbose) module = imp.load_source(filename[:-3], os.path.join(path, filename)) test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module)) if run: unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)