Skip to content
Snippets Groups Projects
Commit d45c883f authored by Ladislav Lhotka's avatar Ladislav Lhotka
Browse files

Reorganize tests.

parent fd4476d9
No related branches found
No related tags found
No related merge requests found
module second-tape {
yang-version 1.1;
namespace "http://example.net/turing-machine/tape-2";
prefix "t2";
import turing-machine {
prefix "tm";
}
description
"This module augments Turing Machine model with second tape.";
revision 2016-04-11 {
description
"Initial revision.";
}
augment "/tm:turing-machine" {
description
"State data for the second tape.";
leaf head-position-2 {
type tm:cell-index;
config "false";
description
"Head position of the second tape.";
}
container tape-2 {
config "false";
description
"Contents of the second tape.";
uses tm:tape-cells;
}
}
augment
"/tm:turing-machine/tm:transition-function/tm:delta/tm:input" {
description
"A new input parameter.";
leaf symbol-2 {
type tm:tape-symbol;
description
"Symbol read from the second tape.";
}
}
augment
"/tm:turing-machine/tm:transition-function/tm:delta/tm:output" {
description
"New output parameters.";
leaf symbol-2 {
type tm:tape-symbol;
description
"Symbol to be written to the second tape. If this leaf is not
present, the symbol doesn't change.";
}
leaf head-move-2 {
type tm:head-dir;
description
"Move the head on the second tape one cell to the left or
right.";
}
}
augment "/tm:initialize/tm:input" {
description
"A new RPC input parameter.";
leaf tape-content-2 {
type string;
description
"Initial content of the second tape.";
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- file: turing-machine-config.xml -->
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<turing-machine xmlns="http://example.net/turing-machine">
<transition-function>
<delta>
<label>left summand</label>
<input>
<state>0</state>
<symbol>1</symbol>
</input>
</delta>
<delta>
<label>separator</label>
<input>
<state>0</state>
<symbol>0</symbol>
</input>
<output>
<state>1</state>
<symbol>1</symbol>
</output>
</delta>
<delta>
<label>right summand</label>
<input>
<state>1</state>
<symbol>1</symbol>
</input>
</delta>
<delta>
<label>right end</label>
<input>
<state>1</state>
<symbol/>
</input>
<output>
<state>2</state>
<head-move>left</head-move>
</output>
</delta>
<delta>
<label>write separator</label>
<input>
<state>2</state>
<symbol>1</symbol>
</input>
<output>
<state>3</state>
<symbol>0</symbol>
<head-move>left</head-move>
</output>
</delta>
<delta>
<label>go home</label>
<input>
<state>3</state>
<symbol>1</symbol>
</input>
<output>
<head-move>left</head-move>
</output>
</delta>
<delta>
<label>final step</label>
<input>
<state>3</state>
<symbol/>
</input>
<output>
<state>4</state>
</output>
</delta>
</transition-function>
</turing-machine>
</config>
<?xml version="1.0" encoding="utf-8"?>
<!-- file: turing-machine-notification.xml -->
<notification
xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
<eventTime>2015-07-08T00:01:00Z</eventTime>
<halted xmlns="http://example.net/turing-machine">
<state>4</state>
</halted>
</notification>
module turing-machine {
yang-version 1.1;
namespace "http://example.net/turing-machine";
prefix "tm";
description
"Data model for the Turing Machine.";
revision 2016-04-11 {
description
"Initial revision.";
}
/* Typedefs */
typedef tape-symbol {
type string {
length "0..1";
}
description
"Type of symbols appearing in tape cells.
A blank is represented as an empty string where necessary.";
}
typedef cell-index {
type int64;
description
"Type for indexing tape cells.";
}
typedef state-index {
type uint16;
description
"Type for indexing states of the control unit.";
}
typedef head-dir {
type enumeration {
enum left;
enum right;
}
default "right";
description
"Possible directions for moving the read/write head, one cell
to the left or right (default).";
}
/* Groupings */
grouping tape-cells {
description
"The tape of the Turing Machine is represented as a sparse
array.";
list cell {
key "coord";
description
"List of non-blank cells.";
leaf coord {
type cell-index;
description
"Coordinate (index) of the tape cell.";
}
leaf symbol {
type tape-symbol {
length "1";
}
description
"Symbol appearing in the tape cell.
Blank (empty string) is not allowed here because the
'cell' list only contains non-blank cells.";
}
}
}
/* State data and Configuration */
container turing-machine {
description
"State data and configuration of a Turing Machine.";
leaf state {
type state-index;
config "false";
mandatory "true";
description
"Current state of the control unit.
The initial state is 0.";
}
leaf head-position {
type cell-index;
config "false";
mandatory "true";
description
"Position of tape read/write head.";
}
container tape {
config "false";
description
"The contents of the tape.";
uses tape-cells;
}
container transition-function {
description
"The Turing Machine is configured by specifying the
transition function.";
list delta {
key "label";
unique "input/state input/symbol";
description
"The list of transition rules.";
leaf label {
type string;
description
"An arbitrary label of the transition rule.";
}
container input {
description
"Input parameters (arguments) of the transition rule.";
leaf state {
type state-index;
mandatory "true";
description
"Current state of the control unit.";
}
leaf symbol {
type tape-symbol;
mandatory "true";
description
"Symbol read from the tape cell.";
}
}
container output {
description
"Output values of the transition rule.";
leaf state {
type state-index;
description
"New state of the control unit. If this leaf is not
present, the state doesn't change.";
}
leaf symbol {
type tape-symbol;
description
"Symbol to be written to the tape cell. If this leaf is
not present, the symbol doesn't change.";
}
leaf head-move {
type head-dir;
description
"Move the head one cell to the left or right";
}
}
}
}
}
/* RPCs */
rpc initialize {
description
"Initialize the Turing Machine as follows:
1. Put the control unit into the initial state (0).
2. Move the read/write head to the tape cell with coordinate
zero.
3. Write the string from the 'tape-content' input parameter to
the tape, character by character, starting at cell 0. The
tape is othewise empty.";
input {
leaf tape-content {
type string;
default "";
description
"The string with which the tape shall be initialized. The
leftmost symbol will be at tape coordinate 0.";
}
}
}
rpc run {
description
"Start the Turing Machine operation.";
}
/* Notifications */
notification halted {
description
"The Turing Machine has halted. This means that there is no
transition rule for the current state and tape symbol.";
leaf state {
type state-index;
mandatory "true";
description
"The state of the control unit in which the machine has
halted.";
}
}
}
{
"ietf-yang-library:modules-state": {
"module-set-id": "",
"module": [
{
"name": "turing-machine",
"revision": "2016-04-11",
"namespace": "http://example.net/turing-machine",
"conformance-type": "implement"
},
{
"name": "second-tape",
"revision": "2016-04-11",
"namespace": "http://example.net/turing-machine/tape-2",
"conformance-type": "implement"
}
]
}
}
from yangson.module.parser import Parser
class TestParser:
text = """module test { // Nice module
prefix t;
namespace /* URI follows */ \t'http://example.com/test';
leaf foo {
type string;
default "hi \\"doc\\"";
}
leaf bar {
mandatory true;
type uint8;
}
}
"""
def test_parser(self):
p = Parser(self.text)
s = p.parse_module()
ss = s.find_all("leaf")
sss1 = ss[0].find1("default")
sss2 = ss[1].find1("type", "uint8")
assert sss1.keyword == "default"
from yangson import DataModel
def test_turing():
tdir = "examples/turing/"
with open(tdir + "yang-library.json", encoding="utf-8") as ylfile:
ylib = ylfile.read()
dm = DataModel.from_yang_library(ylib, tdir)
top = dm.get_data_node("/turing-machine:turing-machine")
assert top.name == "turing-machine"
assert top.ns == "turing-machine"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment