
from unittest import main, TestCase
from grammpy import Rule
from .grammar import *


class NongrammarEntitiesTest(TestCase):
    pass


if __name__ == '__main__':
    main()

from unittest import main, TestCase
from grammpy import Rule, Nonterminal as _N
from grammpy.exceptions import TerminalDoesNotExistsException, NonterminalDoesNotExistsException
from .grammar import *


class Invalid(_N):
    pass


class NongrammarEntitiesTest(TestCase):
    def test_invalidTerminal(self):
        class tmp(Rule):
            rules = [([NFifth], [5, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidTerminalFrom(self):
        class tmp(Rule):
            rules = [(['asdf', NFifth], [2, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidTerminalMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     ([NFifth], [5, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidTerminalFromMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     (['asdf', NFifth], [2, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminal(self):
        class tmp(Rule):
            rules = [([NFifth], [2, Invalid])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminalFrom(self):
        class tmp(Rule):
            rules = [(['a', Invalid], [2, NFirst])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminalMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     ([NFifth], [2, Invalid])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminalFromMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     (['a', Invalid], [2, NFirst])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)


if __name__ == '__main__':
    main()

Add tests of terminals and nonterminals that are not in grammar
Add tests of terminals and nonterminals that are not in grammar

  
  from unittest import main, TestCase
- from grammpy import Rule
+ from grammpy import Rule, Nonterminal as _N
+ from grammpy.exceptions import TerminalDoesNotExistsException, NonterminalDoesNotExistsException
  from .grammar import *
  
  
+ class Invalid(_N):
+     pass
+ 
+ 
  class NongrammarEntitiesTest(TestCase):
-     pass
+     def test_invalidTerminal(self):
+         class tmp(Rule):
+             rules = [([NFifth], [5, NFirst])]
+         with self.assertRaises(TerminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidTerminalFrom(self):
+         class tmp(Rule):
+             rules = [(['asdf', NFifth], [2, NFirst])]
+         with self.assertRaises(TerminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidTerminalMultiple(self):
+         class tmp(Rule):
+             rules = [([TSecond, 'b', TThird], ['c', 2]),
+                      ([NFifth], [5, NFirst])]
+         with self.assertRaises(TerminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidTerminalFromMultiple(self):
+         class tmp(Rule):
+             rules = [([TSecond, 'b', TThird], ['c', 2]),
+                      (['asdf', NFifth], [2, NFirst])]
+         with self.assertRaises(TerminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidNonterminal(self):
+         class tmp(Rule):
+             rules = [([NFifth], [2, Invalid])]
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidNonterminalFrom(self):
+         class tmp(Rule):
+             rules = [(['a', Invalid], [2, NFirst])]
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidNonterminalMultiple(self):
+         class tmp(Rule):
+             rules = [([TSecond, 'b', TThird], ['c', 2]),
+                      ([NFifth], [2, Invalid])]
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             tmp.validate(grammar)
+ 
+     def test_invalidNonterminalFromMultiple(self):
+         class tmp(Rule):
+             rules = [([TSecond, 'b', TThird], ['c', 2]),
+                      (['a', Invalid], [2, NFirst])]
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             tmp.validate(grammar)
  
  
  if __name__ == '__main__':
      main()
+ 
Add tests of terminals and nonterminals that are not in grammar
## Code Before:

from unittest import main, TestCase
from grammpy import Rule
from .grammar import *


class NongrammarEntitiesTest(TestCase):
    pass


if __name__ == '__main__':
    main()
## Instruction:
Add tests of terminals and nonterminals that are not in grammar
## Code After:

from unittest import main, TestCase
from grammpy import Rule, Nonterminal as _N
from grammpy.exceptions import TerminalDoesNotExistsException, NonterminalDoesNotExistsException
from .grammar import *


class Invalid(_N):
    pass


class NongrammarEntitiesTest(TestCase):
    def test_invalidTerminal(self):
        class tmp(Rule):
            rules = [([NFifth], [5, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidTerminalFrom(self):
        class tmp(Rule):
            rules = [(['asdf', NFifth], [2, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidTerminalMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     ([NFifth], [5, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidTerminalFromMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     (['asdf', NFifth], [2, NFirst])]
        with self.assertRaises(TerminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminal(self):
        class tmp(Rule):
            rules = [([NFifth], [2, Invalid])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminalFrom(self):
        class tmp(Rule):
            rules = [(['a', Invalid], [2, NFirst])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminalMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     ([NFifth], [2, Invalid])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)

    def test_invalidNonterminalFromMultiple(self):
        class tmp(Rule):
            rules = [([TSecond, 'b', TThird], ['c', 2]),
                     (['a', Invalid], [2, NFirst])]
        with self.assertRaises(NonterminalDoesNotExistsException):
            tmp.validate(grammar)


if __name__ == '__main__':
    main()
