"""Tests for known XML attacks"""

from os import path
from unittest import TestCase

from psutil import Process

from parsel import Selector


MiB_1 = 1024^2


def _load(attack):
    folder_path = path.dirname(__file__)
    file_path = path.join(folder_path, 'xml_attacks', '{}.xml'.format(attack))
    with open(file_path) as attack_file:
        return attack_file.read()


# List of known attacks:
# https://github.com/tiran/defusedxml#python-xml-libraries
class XMLAttackTestCase(TestCase):

    def test_billion_laughs(self):
        process = Process()
        memory_usage_before = process.memory_info().rss
        selector = Selector(text=_load('billion_laughs'))
        lolz = selector.css('lolz::text').get()
        memory_usage_after = process.memory_info().rss
        memory_change = (memory_usage_after - memory_usage_before)
        assert memory_change <= MiB_1
        assert lolz == '&lol9;'

"""Tests for known XML attacks"""

from os import path
from unittest import TestCase

from psutil import Process

from parsel import Selector


MiB_1 = 1024 ^ 2


def _load(attack):
    folder_path = path.dirname(__file__)
    file_path = path.join(folder_path, 'xml_attacks', '{}.xml'.format(attack))
    with open(file_path) as attack_file:
        return attack_file.read()


# List of known attacks:
# https://github.com/tiran/defusedxml#python-xml-libraries
class XMLAttackTestCase(TestCase):

    def test_billion_laughs(self):
        process = Process()
        memory_usage_before = process.memory_info().rss
        selector = Selector(text=_load('billion_laughs'))
        lolz = selector.css('lolz::text').get()
        memory_usage_after = process.memory_info().rss
        memory_change = (memory_usage_after - memory_usage_before)
        assert memory_change <= MiB_1
        assert lolz == '&lol9;'

Fix Flake8-reported issues