Пример #1
0
	def load(self, filename):
		"""
		Loads profile from vdf file. Returns self.
		May raise ValueError.
		"""
		data = parse_vdf(open(filename, "r"))
		self.load_data(data)
Пример #2
0
    def load(self, filename):
        """
		Loads profile from vdf file. Returns self.
		May raise ValueError.
		"""
        data = parse_vdf(open(filename, "r"))
        self.load_data(data)
Пример #3
0
class VDFFZProfile(VDFProfile):
	def load(self, filename):
		try:
			data = json.loads(open(filename, "r").read())
		except Exception, e:
			raise ValueError("Failed to parse JSON")
		if 'ConfigData' not in data:
			raise ValueError("ConfigData missing in JSON")
		self.load_data(parse_vdf(data['ConfigData'].encode('utf-8')))
	def test_unclosed_bracket(self):
		"""
		Tests if VDF parser throws exception when there is unclosed {
		"""
		sio = StringIO("""
		"data"
		{
			"version" "3"
			"more data" {
				"version" "7"
			}
		""")
		with pytest.raises(ValueError) as excinfo:
			parsed = parse_vdf(sio)
	def test_parsing(self):
		""" Tests if VDF parser parses VDF """
		sio = StringIO("""
		"data"
		{
			"version" "3"
			"more data" {
				"version" "7"
			}
		}
		""")
		parsed = parse_vdf(sio)
		assert type(parsed["data"]) == dict
		assert parsed["data"]["version"] == "3"
		assert parsed["data"]["more data"]["version"] == "7"
	def test_dict_without_key(self):
		"""
		Tests if VDF parser throws exception when there is dict with key missing
		"""
		sio = StringIO("""
		"data"
		{
			"version" "3"
			{
				"version" "7"
			}
		}
		""")
		with pytest.raises(ValueError) as excinfo:
			parsed = parse_vdf(sio)
	def test_too_many_brackets(self):
		"""
		Tests if VDF parser throws exception when there is } wihtout matching {
		"""
		sio = StringIO("""
		"data"
		{
			"version" "3"
			"more data" {
				"version" "7"
			}
			}
		}
		""")
		with pytest.raises(ValueError) as excinfo:
			parsed = parse_vdf(sio)