Exemplo n.º 1
0
def test_2():
    """Create network that matches test definition file 2"""
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)

    CK1, CK2, AND1, NAND1, OR1, NOR1 = names.lookup(
        ["CK1", "CK2", "AND1", "NAND1", "OR1", "NOR1"])
    devices.make_device(CK1, devices.CLOCK, 2)
    devices.make_device(CK2, devices.CLOCK, 1)
    devices.make_device(AND1, devices.AND, 2)
    devices.make_device(NAND1, devices.NAND, 2)
    devices.make_device(OR1, devices.OR, 2)
    devices.make_device(NOR1, devices.NOR, 2)

    network.make_connection(CK1, None, AND1, names.query("I1"))
    network.make_connection(CK2, None, AND1, names.query("I2"))
    network.make_connection(CK2, None, NAND1, names.query("I2"))
    network.make_connection(CK2, None, OR1, names.query("I2"))
    network.make_connection(CK2, None, NOR1, names.query("I2"))
    network.make_connection(AND1, None, NAND1, names.query("I1"))
    network.make_connection(NAND1, None, OR1, names.query("I1"))
    network.make_connection(OR1, None, NOR1, names.query("I1"))

    monitors.make_monitor(NOR1, None)
    return names, devices, network, monitors
Exemplo n.º 2
0
    def run_parser(self, file_path):
        """Call parse_network() from path specified.

        To do so first reinitzialize all modules and cycles_completed.
        """
        # clear all at the begging
        self.cycles_completed = 0
        self.names = Names()
        self.devices = Devices(self.names)
        self.network = Network(self.names, self.devices)
        self.monitors = Monitors(self.names, self.devices, self.network)
        self.scanner = Scanner(file_path, self.names)
        self.parser = Parser(self.names, self.devices, self.network,
                             self.monitors, self.scanner)
        # Capture the stdout from parse_network()
        captured_stdout = io.StringIO()
        with redirect_stdout(captured_stdout):
            if self.parser.parse_network():
                self.parse_success = True
                self.log_message(_("Succesfully parsed network."))
            else:
                self.parse_success = False
                self.log_message(_("Failed to parse network."))
                # Show error messages captured in activity log
                self.log_message(captured_stdout.getvalue(),
                                 self.MONOSPACE_FONT)
Exemplo n.º 3
0
def test_1():
    """Create network that matches test definition file 1"""
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)

    [SW1, SW2, SW3, SW4, D1, CK1, XOR1] = \
        names.lookup(["SW1", "SW2", "SW3", "SW4", "D1", "CK1", "XOR1"])
    print(names.query("SW1"))
    devices.make_device(SW1, devices.SWITCH, 1)
    devices.make_device(SW2, devices.SWITCH, 1)
    devices.make_device(SW3, devices.SWITCH, 1)
    devices.make_device(SW4, devices.SWITCH, 0)
    devices.make_device(D1, devices.D_TYPE)
    devices.make_device(CK1, devices.CLOCK, 2)
    devices.make_device(XOR1, devices.XOR)

    network.make_connection(SW1, None, XOR1, names.query("I1"))
    network.make_connection(SW2, None, XOR1, names.query("I2"))
    network.make_connection(XOR1, None, D1, names.query("DATA"))
    network.make_connection(CK1, None, D1, names.query("CLK"))
    network.make_connection(SW3, None, D1, names.query("SET"))
    network.make_connection(SW4, None, D1, names.query("CLEAR"))

    monitors.make_monitor(D1, names.query("Q"))
    monitors.make_monitor(D1, names.query("QBAR"))

    return names, devices, network, monitors
Exemplo n.º 4
0
def new_names_with_items():
    '''returns an instance of class Names with items '''
    new_names_with_items = Names()
    new_names_with_items.lookup([
        'DEVICE', 'CONNECT', 'MONITOR', 'CLOCK', 'SWITCH', 'AND', 'NAND', 'G2'
    ])
    return new_names_with_items
Exemplo n.º 5
0
 def __init__(self):
     self.__cars = list()
     car_names = Names()
     name = car_names.get_next_name()
     while name:
         self.__cars.append(Car(name))
         name = car_names.get_next_name()
Exemplo n.º 6
0
def devices_with_items():
    """Return a Devices class instance with three devices in the network."""
    new_names = Names()
    new_devices = Devices(new_names)

    [AND1_ID, NOR1_ID, SW1_ID] = new_names.lookup(["And1", "Nor1", "Sw1"])

    new_devices.make_device(AND1_ID, new_devices.AND, 2)
    new_devices.make_device(NOR1_ID, new_devices.NOR, 16)
    new_devices.make_device(SW1_ID, new_devices.SWITCH, 0)

    return new_devices
Exemplo n.º 7
0
def network_with_devices():
    """Return a Network class instance with three devices in the network."""
    new_names = Names()
    new_devices = Devices(new_names)
    new_network = Network(new_names, new_devices)

    [SW1_ID, SW2_ID, OR1_ID] = new_names.lookup(["Sw1", "Sw2", "Or1"])

    # Add devices
    new_devices.make_device(SW1_ID, new_devices.SWITCH, 0)
    new_devices.make_device(SW2_ID, new_devices.SWITCH, 0)
    new_devices.make_device(OR1_ID, new_devices.OR, 2)

    return new_network
Exemplo n.º 8
0
def main():

    # Initialise instances of the four inner simulator classes
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)

    [s1, s2] = devices.names.lookup(["S1", "S2"])

    devices.make_switch(s1, 0)
    devices.make_switch(s2, 0)
    devices.make_gate(1, devices.names.query("NAND"), 2)
    devices.make_gate(2, devices.names.query("NAND"), 2)

    network.make_connection(s1, None, 1, devices.names.query("I1"))
    network.make_connection(s2, None, 2, devices.names.query("I2"))
    network.make_connection(1, None, 2, devices.names.query("I1"))
    network.make_connection(2, None, 1, devices.names.query("I2"))
    print(network.check_network())

    print(monitors.make_monitor(1, None))
    monitors.display_signals()

    userint = UserInterface(names, devices, network, monitors)
    userint.command_interface()
Exemplo n.º 9
0
def devices_with_items():
    """Return a Devices class instance with four devices in the network."""
    new_names = Names()
    new_devices = Devices(new_names)

    [AND1_ID, NOR1_ID, SW1_ID, SIGGEN_ID] = new_names.lookup(["And1", "Nor1",
                                                              "Sw1",
                                                              "Siggen1"])

    new_devices.make_device(AND1_ID, new_devices.AND, [2])
    new_devices.make_device(NOR1_ID, new_devices.NOR, [16])
    new_devices.make_device(SW1_ID, new_devices.SWITCH, [0])
    new_devices.make_device(SIGGEN_ID, new_devices.SIGGEN, [0, 1, 1, 1, 0])
    print(new_devices.find_devices())

    return new_devices
Exemplo n.º 10
0
 def __init__(self, model, symbolTable):
     self.model = model
     self.symbolTable = symbolTable
     self.mcrl2 = []
     self.line = deque([])
     self.errors = [];
     self.nameGen = Names(symbolTable, 'mcrl2')
Exemplo n.º 11
0
 def test_names_real_file(self):
     names = Names().from_file('adult.names')
     self.assertEqual(names.size(), 15)
     stat = Statistics(names)
     map_to_numeric = {}
     map_to_numeric[names.target_feature] = {}
     map_to_numeric[names.target_feature][names.feature[
         names.target_feature].values[0]] = 1
     map_to_numeric[names.target_feature][names.feature[
         names.target_feature].values[1]] = 0
     stat.process_file('adult.data', names, map_to_numeric)
     trans = Transform(names)
     trans.monotone_from_stat(stat)
     trans.print_names('adult_transformed.names')
     trans.transform_file('adult.data', 'adult_transformed.data')
     trans.transform_file('adult.test', 'adult_transformed.test')
Exemplo n.º 12
0
def new_parser(path):
    """Return a new instance of the Parser class."""
    new_names = Names()
    new_scan = Scanner(path, new_names)
    new_devices = Devices(new_names)
    new_network = Network(new_names, new_devices)
    new_monitors = Monitors(new_names, new_devices, new_network)
    return Parser(new_names, new_devices, new_network, new_monitors, new_scan)
Exemplo n.º 13
0
def startup_parser(data):
    new_names = Names()
    new_scan = Scanner(data, new_names, True)
    new_devices = Devices(new_names)
    new_network= Network(new_names, new_devices)
    new_monitors = Monitors(new_names, new_devices, new_network)
    parse = Parser(new_names, new_devices, new_network, new_monitors, new_scan)
    return parse
Exemplo n.º 14
0
def create_parser(path):
    """Create a new parser for every test"""
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)
    scanner = Scanner(path, names)
    parser = Parser(names, devices, network, monitors, scanner)
    return parser
Exemplo n.º 15
0
def main(arg_list):
    """Parse the command line options and arguments specified in arg_list.

    Run either the command line user interface, the graphical user interface,
    or display the usage message.
    """
    usage_message = ("Usage:\n"
                     "Show help: logsim.py -h\n"
                     "Command line user interface: logsim.py -c <file path>\n"
                     "Graphical user interface: logsim.py <file path>")
    try:
        options, arguments = getopt.getopt(arg_list, "hc:")
    except getopt.GetoptError:
        print("Error: invalid command line arguments\n")
        print(usage_message)
        sys.exit()

    # Initialise instances of the four inner simulator classes
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)

    for option, path in options:
        if option == "-h":  # print the usage message
            print(usage_message)
            sys.exit()
        elif option == "-c":  # use the command line user interface
            scanner = Scanner(path, names)
            parser = Parser(names, devices, network, monitors, scanner)
            if parser.parse_network():
                # Initialise an instance of the userint.UserInterface() class
                userint = UserInterface(names, devices, network, monitors)
                userint.command_interface()

    if not options:  # no option given, use the graphical user interface

        if len(arguments) != 1:  # wrong number of arguments
            print("Error: one file path required\n")
            print(usage_message)
            sys.exit()

        [path] = arguments
        scanner = Scanner(path, names)
        parser = Parser(names, devices, network, monitors, scanner)
        if parser.parse_network():
            # Initialise an instance of the gui.Gui() class
            app = wx.App()
            builtins._ = wx.GetTranslation
            locale = wx.Locale()
            locale.Init(wx.LANGUAGE_DEFAULT)
            locale.AddCatalogLookupPathPrefix('./locale')
            locale.AddCatalog('zh_CN')
            gui = Gui("Logic Simulator", path, names, devices, network,
                      monitors)
            gui.Show(True)
            app.MainLoop()
Exemplo n.º 16
0
def new_parser():
    # Build a fixture and all the following tests uses it
    path = 'test_def.txt'
    names = Names()
    scanner = Scanner(path, names)
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)
    new_parser = Parser(names, devices, network, monitors, scanner)
    return new_parser
Exemplo n.º 17
0
def new_parser():
    """Return a new parser instance."""
    
    file_name = 'file.txt'
    new_names = Names()
    new_devices = Devices(new_names)
    new_network = Network(new_names, new_devices)
    new_monitors = Monitors(new_names, new_devices, new_network) 
    new_scanner = Scanner(file_name, new_names) 
    return Parser(new_names, new_devices, new_network, new_monitors, new_scanner) 
Exemplo n.º 18
0
def parser_device():
    """Return a new instance of the Parse class."""
    names = Names()
    scanner = Scanner(file_device, names)
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)
    new_parser = Parser(names, devices, network, monitors, scanner)

    return new_parser
Exemplo n.º 19
0
def create_parser(input_file):
    """Return a new parser instance."""
    path = "./test_specfiles/test_parse/" + input_file
    # Initialise instances of the four inner simulator classes
    names = Names()
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)
    scanner = Scanner(path, names)
    return Parser(names, devices, network, monitors, scanner)
Exemplo n.º 20
0
def test_unique_error_codes():
    """Test the unique_error_codes method"""
    n = Names()
    codes = n.unique_error_codes(3)
    assert [codes[0], codes[1], codes[2]] == [0, 1, 2]
    with pytest.raises(TypeError):
        n.unique_error_codes(-1)
    with pytest.raises(TypeError):
        n.unique_error_codes("s")
Exemplo n.º 21
0
def new_parser_with_errors():
    """Return a new instance of the Parse class."""
    new_names = Names()
    new_scanner = Scanner(file_errors, new_names)
    new_devices = Devices(new_names)
    new_network = Network(new_names, new_devices)
    new_monitors = Monitors(new_names, new_devices, new_network)
    new_parser = Parser(new_names, new_devices, new_network, new_monitors,
                        new_scanner)

    return new_parser
Exemplo n.º 22
0
    def __init__(self, model, symbolTable, package, root_package):
        self.model = model
        self.symbolTable = symbolTable
        self.package = package
        self.root_package = root_package

        self.namegen = Names(symbolTable, 'java')
        self.files = {}  # All files
        self.fileName = None  # Current file name
        self.lines = []
        self.line = deque([])  # Current line
        self.errors = []
Exemplo n.º 23
0
def filled_names(sample_names_list):
    """Return a Names class with three error codes and
    three names."""
    new_names = Names()
    new_names.unique_error_codes(3)
    new_names.lookup(sample_names_list)
    return new_names
Exemplo n.º 24
0
def main():
    '''the main'''
    message('main called')

    args = arg_parser()
    wrkday = parse_wrkday(args)

    if wrkday:
        for gate in getgatelist().keys():
            gtn = Names(gate, wrkday)

            if not args.nonet:

                if wrkday.date() == Dates(date.today()).date():
                    message('this is today, say cheese', shout=True)
                    message(gtn.snapshot(), shout=True)
                    message(gtn.remotecommands(), shout=True)
                message('trying to load graph', shout=True)
                message(gtn.getsnapshot(), shout=True)

            message('writing article', shout=True)
            gtn.mkpost()

        message('feeding the pelican', shout=True)
        mkpelican()

        message('all done', shout=True)
Exemplo n.º 25
0
def test_query():
    """Test the query method"""
    n = Names()
    n.names = ["name1", "name2", "name3"]
    assert n.query("name1") == 0
    assert n.query("name4") is None
    assert n.query(2) is None
    assert n.query(-1) is None
Exemplo n.º 26
0
def test_get_name_string():
    """Test the get_name_string method"""
    n = Names()
    _ = n.lookup(["name1", "name2", "name3"])
    assert n.get_name_string(1) == "name2"
    assert n.get_name_string(5) is None
    with pytest.raises(TypeError):
        n.get_name_string('a')
Exemplo n.º 27
0
def test_lookup():
    """Test the look_up method"""
    n = Names()
    assert n.lookup(["name1"]) == [0]
    assert n.lookup(["name2"]) == [1]
    assert n.lookup(["name2", "name3", "name1"]) == [1, 2, 0]
    assert n.query("name1") == 0
    assert n.query(-1) is None
Exemplo n.º 28
0
def deviceline_parser():
    """Return a new instance of the Parser module, using a test
    description file."""
    new_names = Names()
    new_scanner = Scanner("test_def_files/for_check_deviceline.txt", new_names)
    new_devices = Devices(new_names)
    new_network = Network(new_names, new_devices)
    new_monitors = Monitors(new_names, new_devices, new_network)
    return Parser(
        new_names,
        new_devices,
        new_network,
        new_monitors,
        new_scanner)
Exemplo n.º 29
0
def parser_connect():
    """Return a new instance of the Parse class."""
    names = Names()
    scanner = Scanner(file_connect, names)
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)
    new_parser = Parser(names, devices, network, monitors, scanner)

    [clk, dt] = new_parser.names.lookup(["CLK", "D1"])
    new_parser.devices.make_device(clk, devices.CLOCK, 10)
    new_parser.devices.make_device(dt, devices.D_TYPE)

    return new_parser
Exemplo n.º 30
0
    def on_menu(self, event):
        """Handle the event when the user selects a menu item."""
        Id = event.GetId()
        if Id == 103:
            exitconf = self.exitconfirmation.ShowModal()
            if exitconf == wx.ID_YES:
                self.Close(True)
        if Id == 102:
            wx.MessageBox(
                _(u"Display the signal traces at different monitored outputs.  \nRed trace represents '1', blue trace represents '0'.\nOutputs to be monitored can be selected by clicking 'Monitor'.\nSwitches levels can be selected by clicking 'Set Switches'"
                  ), _(u"About Logsim"), wx.ICON_INFORMATION | wx.OK)

        if Id == wx.ID_OPEN:
            with wx.FileDialog(self) as fileDialog:
                if fileDialog.ShowModal() == wx.ID_CANCEL:
                    return
                path = fileDialog.GetPath()
                self.Close(True)

                app = wx.App()
                error = ErrorFrame()

                names = Names()
                devices = Devices(names)
                network = Network(names, devices)
                monitors = Monitors(names, devices, network)
                self.names = names
                self.devices = devices
                self.network = network
                self.monitors = monitors
                self.scanner = Scanner(path, self.names)
                self.parser = Parser(self.names, self.devices, self.network,
                                     self.monitors, self.scanner)
                global global_cycles_completed
                global hold
                global hold_monitor
                global_cycles_completed = 0
                hold = {}
                hold_monitor = {}
                try:
                    self.parser.parse_network()
                    gui = Gui("LogicSim", path, self.names, self.devices,
                              self.network, self.monitors)
                    gui.Show(True)
                except:
                    pass

                error.ShowModal()
                app.MainLoop()
Exemplo n.º 31
0
def parser_io():
    """Return a new instance of the Parse class."""
    names = Names()
    scanner = Scanner(file_io, names)
    devices = Devices(names)
    network = Network(names, devices)
    monitors = Monitors(names, devices, network)
    new_parser = Parser(names, devices, network, monitors, scanner)

    # Initially populate new_devices with some devices
    [new_parser.DT] = new_parser.names.lookup(["d1"])

    new_parser.devices.make_device(new_parser.DT, devices.D_TYPE)

    return new_parser