Exemple #1
0
class FileReaderTestCase(unittest.TestCase):
    def setUp(self):
        """
        manitest file location: ../manifests/opencart.txt
        with following contents
        -----------------------------------
        basepath=/home/vineet/public_html/
        basedir=opencart_v1.4.9.4

        index.php
        catalog/controller/account/account.php
        catalog/controller/account/create.php
        catalog/controller/feed/*
        catalog/model/**
        -----------------------------------
        """
        self.file = '../manifests/opencart.txt'
        self.reader = FileReader(self.file)

    def test_reader_type(self):
        self.assertEqual(FileReader.reader_type, 'file')

    def test_init(self):
        self.assertEqual(self.reader.file, self.file)

    def test_get_property(self):
        """
        This is just a static method.
        so just providing the input params
        """
        line = 'basepath=/home/vineet/public_html/'
        self.assertEqual(FileReader.get_property(line),
                         '/home/vineet/public_html/')

    def test_get_lines(self):
        lines = self.reader.get_lines()
        self.assertEqual(len(lines), 8 + 1)
        self.assertEqual(lines[2], '')
        self.assertEqual(lines[3], 'index.php')
        self.assertEqual(lines[7], 'catalog/model/**')

    def test_get_config(self):
        config = self.reader.get_config()
        self.assertEqual(config['source_base_path'],
                         '/home/vineet/public_html/')
        self.assertEqual(config['source_dir'], 'opencart_v1.4.9.4')
        self.assertEqual(config['source_path'],
                         '/home/vineet/public_html/opencart_v1.4.9.4/')
        self.assertEqual(config['target_dir'], '../target/opencart_v1.4.9.4/')
        self.assertEqual(len(config['lines']), 8 + 1 - 2)
Exemple #2
0
 def test_iter_file(self):
     expected = ["Hola, esta\n", "es una cadena\n", "de texto\n"]
     with FileReader(textfile) as reader:
         assert reader.encoding == "utf-8"
         assert reader.filename == textfile
         for line, expected_line in zip(reader, expected):
             assert line == expected_line
Exemple #3
0
 def test_get_property(self):
     """
     This is just a static method.
     so just providing the input params
     """
     line = 'basepath=/home/vineet/public_html/'
     self.assertEqual(FileReader.get_property(line), '/home/vineet/public_html/')
Exemple #4
0
class FileReaderTestCase(unittest.TestCase):
    def setUp(self):
        """
        manitest file location: ../manifests/opencart.txt
        with following contents
        -----------------------------------
        basepath=/home/vineet/public_html/
        basedir=opencart_v1.4.9.4

        index.php
        catalog/controller/account/account.php
        catalog/controller/account/create.php
        catalog/controller/feed/*
        catalog/model/**
        -----------------------------------
        """
        self.file = '../manifests/opencart.txt'
        self.reader = FileReader(self.file)

    def test_reader_type(self):
        self.assertEqual(FileReader.reader_type, 'file')

    def test_init(self):
        self.assertEqual(self.reader.file, self.file)

    def test_get_property(self):
        """
        This is just a static method.
        so just providing the input params
        """
        line = 'basepath=/home/vineet/public_html/'
        self.assertEqual(FileReader.get_property(line), '/home/vineet/public_html/')

    def test_get_lines(self):
        lines = self.reader.get_lines()
        self.assertEqual(len(lines), 8+1)
        self.assertEqual(lines[2], '')
        self.assertEqual(lines[3], 'index.php')
        self.assertEqual(lines[7], 'catalog/model/**')

    def test_get_config(self):
        config = self.reader.get_config()
        self.assertEqual(config['source_base_path'], '/home/vineet/public_html/')
        self.assertEqual(config['source_dir'], 'opencart_v1.4.9.4')
        self.assertEqual(config['source_path'], '/home/vineet/public_html/opencart_v1.4.9.4/')
        self.assertEqual(config['target_dir'], '../target/opencart_v1.4.9.4/')
        self.assertEqual(len(config['lines']), 8+1-2)
Exemple #5
0
 def test_get_property(self):
     """
     This is just a static method.
     so just providing the input params
     """
     line = 'basepath=/home/vineet/public_html/'
     self.assertEqual(FileReader.get_property(line),
                      '/home/vineet/public_html/')
Exemple #6
0
    def setUp(self):
        """
        manitest file location: ../manifests/opencart.txt
        with following contents
        -----------------------------------
        basepath=/home/vineet/public_html/
        basedir=opencart_v1.4.9.4

        index.php
        catalog/controller/account/account.php
        catalog/controller/account/create.php
        catalog/controller/feed/*
        catalog/model/**
        -----------------------------------
        """
        self.file = '../manifests/opencart.txt'
        self.reader = FileReader(self.file)
 def test_write_to_file(self):
     """
     Testing write to file
     Writing and array to file and then reading the files and comparing if they have been written properly
     :return:
     """
     content = ['the quick brown fox', 'jumps over the lazy', 'dog']
     filepath = 'resources/test/out/write.txt'
     Utils.write_to_file(filepath, content)
     read_content = FileReader.read(filepath)
     self.assertEqual(content, read_content)
Exemple #8
0
def initialize_scanner(source_path):
    reader = FileReader(source_path)
    machine = Scanner(reader)

    machine.add_state('start', start_state_transition)
    machine.add_state('a', a_state_transition)
    machine.add_state('b', b_state_transition)
    machine.add_state('c', c_state_transition)
    machine.add_state('d', d_state_transition)
    machine.add_state('id', None, end_state=True)
    machine.add_state('digit', None, end_state=True)
    machine.add_state('operator', None, end_state=True)

    machine.set_start('start')

    return machine
Exemple #9
0
    def setUp(self):
        """
        manitest file location: ../manifests/opencart.txt
        with following contents
        -----------------------------------
        basepath=/home/vineet/public_html/
        basedir=opencart_v1.4.9.4

        index.php
        catalog/controller/account/account.php
        catalog/controller/account/create.php
        catalog/controller/feed/*
        catalog/model/**
        -----------------------------------
        """
        self.file = '../manifests/opencart.txt'
        self.reader = FileReader(self.file)
Exemple #10
0
def get_reader(cmd_argv):
    """
    function to get the correct reader object as per the command
    """
    if cmd_argv[1] == '--file':
        reader = FileReader(cmd_argv[2])
    elif cmd_argv[1] == '--git':
        args = cmd_argv[2:]
        wd = args.pop(0)
        hash1 = args.pop(0)
        try:
            hash2 = args.pop(0)
        except IndexError:
            hash2 = None
        reader = GitReader(wd, hash1, hash2)
    else:
        raise UnsupportedReaderError(cmd_argv[1])
    return reader
Exemple #11
0
def init():
    # Setup DAQ Readers
    DAQreader['micreader'] = {'reader': MicReader.MicReader(), 'name': "Mic"}
    DAQreader['randomreader'] = {
        'reader': RandomReader.RandomReader(),
        'name': 'Random'
    }
    try:
        DAQreader['delsysreader'] = {
            'reader': DelsysReader.DelsysReader(),
            'name': 'Delsys'
        }
    except Exception as e:
        print("ERROR With Delsys")

    # Setup File Reader
    filereader['reader'] = FileReader.FileReader()

    return jsonify(1)
    def invite_customers(self):
        try:

            if 'http' in self.input_path:
                # Reading from file over http
                customers_list = HttpReader.read(self.input_path)
            else:
                # Reading from File on local system
                customers_list = FileReader.read(self.input_path)

            # Creating customer objects from json
            customers = self.create_customer_objects(customers_list)

            # Filtering customers on the basis of the distance threshold
            filtered_customers = self.filter_customers_by_distance(customers)

            # Inviting customer
            self.send_invites(filtered_customers)

            return filtered_customers

        except KeyError as ke:
            print("KeyError encountered")
            traceback.print_exc(file=sys.stdout)
        except ValueError as ve:
            print("ValueError encounterd")
            traceback.print_exc(file=sys.stdout)
        except URLError as ue:
            print("Error getting data from url")
            traceback.print_exc(file=sys.stdout)
        except FileNotFoundError as fe:
            print("Unable to find file")
            traceback.print_exc(file=sys.stdout)
        except Exception as e:
            print("Some error occurred")
            traceback.print_exc(file=sys.stdout)
Exemple #13
0
 def test_open_fails(self):
     f = FileReader('wrong file that does not exist')
     with raises(FileNotFoundError):
         f.open()
 def test_file_reader_empty(self):
     path = 'resources/test/texts/empty.txt'
     content = FileReader.read(path)
     correct_list = []
     self.assertListEqual(content, correct_list)
Exemple #15
0
# TODO see if there are different ASNs for both the one we queried and the one who queries our servers
# example of how to call: python PlotMain.py C:/Users/tyler/PycharmProjects/PlottingPractice/datalib

################################################################################################################
# This program reads all data files that are created from the data gathered by running a fullscan of ipv4 space
# This includes maxudp data, p0f, ASN, and geolocation. In essence this program gathers all the data into one
# point for ease of use. All data is put into two dictionaries. One, variable_dict, has each possible variable
# as a key for
################################################################################################################
# READ IN THE DATA FROM OUR FILES

if len(sys.argv) != 2:
    print("Invalid, Usage: python PlotMain.py {}\n".format("<DataFilesPath>"))
    exit(1)
directory = sys.argv[1]
fileReader = File_Reader.FileReader(directory)

# All files we are reading should be in one directory given as an argument
# Read in all the files
print("Reading all files...\n")
data_holders = fileReader.read_all_files()
d = data_holders.get_value_dict("country")

######################################################################################################
# BEGIN PROCESSING THE DATA
print("All possible keys are as follows: ")
for key in data_holders.all_possible_keys:
    print("%s " % key)

######################################################################################################
# Write data out to files
 def test_file_reader_found(self):
     path = 'resources/test/texts/some.txt'
     correct_list = ['the quick brown fox', 'jumps over the lazy', 'dog']
     content = FileReader.read(path)
     self.assertListEqual(content, correct_list)
Exemple #17
0
 def test__init__(self):
     f = FileReader(textfile)
     assert f.filename == textfile
     assert f.encoding == "utf-8"
     assert not f.is_open
     assert f.file is None
Exemple #18
0
 def test_open_closed_ok(self):
     f = FileReader(textfile)
     f.open()
     assert f.is_open
     f.close()
     assert not f.is_open
Exemple #19
0
 def test_whole_file(self):
     expected = "Hola, esta\nes una cadena\nde texto\n"
     result = FileReader(textfile).read()
     assert result == expected
Exemple #20
0
 def test__enter__(self):
     with FileReader(textfile) as reader:
         assert reader.is_open
     assert not reader.is_open