def testFileRead(self): ## test existing file cont = SysUtils.readFileContent("content.txt") self.assertEqual(cont, "hello") ## test non-existing file cont = SysUtils.readFileContent("nosuchfile.txt") self.assertIsNone(cont)
def load(self, inFile): ## load configuration from argument or ./config.cfg.json or config/config.cfg.json cfgFile = inFile or ("config.cfg.json" if os.path.isfile("config.cfg.json") else os.path.join("config", "config.cfg.json")) if (not os.path.isfile(cfgFile)): raise ConfigException("unable to find config file") self.cfgFile = cfgFile content = SysUtils.readFileContent(cfgFile) self.json = json.loads(content)
def loadTermFile(self, ruleFile): if not os.path.exists(ruleFile): cfgDirecotry = os.path.dirname(os.path.abspath(Config.getConfigFile())) ## pick at config directory ruleFile = os.path.join(cfgDirecotry, ruleFile) if not os.path.exists(ruleFile): raise NLPException("Unable to load rule file " + os.path.basename(ruleFile)) return json.loads(SysUtils.readFileContent(ruleFile))
def testJsonParser(self): fileData = json.loads(SysUtils.readFileContent("testJson.json")) parser = Parser.Factory.getParser("json") parser.parseFile("testJson.json") self.assertSequenceEqual(parser.docs(), fileData["docs"]) self.assertEqual(parser.getFileMetaData("metaData"), "some data")
def parseFile(self, fileName): self.json = json.loads(SysUtils.readFileContent(fileName))