示例#1
0
  def testLetterIsNotAVowel(self):
    poetry = Poetry()
    letter = "r"

    results = poetry.isVowel(letter, 2, 3)  # factory boy?

    self.assertEqual(False, results)
示例#2
0
  def testLetterIsAVowel(self):
    poetry = Poetry()
    letter = "a"

    results = poetry.isVowel(letter, 2, 3)  # factory boy?

    self.assertEqual(True, results)  # AssertionError
示例#3
0
  def testCharacterIsLetter(self):
    poetry    = Poetry()
    character = "a"

    results = poetry.isLetter(character)

    self.assertEqual(True, results)
示例#4
0
  def testBlankLineLastWord(self):
    poetry   = Poetry()
    line     = "     "
    expected = ""

    results = poetry._lastWord(line)

    self.assertEqual(expected, results)
示例#5
0
  def testOnlyWordLastWord(self):
    poetry   = Poetry()
    line     = "problem"
    expected = "problem"

    results = poetry._lastWord(line)

    self.assertEqual(expected, results)
示例#6
0
  def testAreRhymingWords(self):
    poetry = Poetry()
    w1 = "pills"
    w2 = "ills"

    results = poetry.areRhymingWords(w1, w2)

    self.assertEqual(True, results)
示例#7
0
  def testYLastIsNotAVowel(self):
    poetry = Poetry()
    letter = "y"

    results = poetry.isVowel(letter, 3, 3)  # y is the last letter, therefore
                                            # it is not a vowel

    self.assertEqual(False, results)
示例#8
0
  def test7(self):
    poetry = Poetry()
    poem = ["too bad   your",
             "     solution went   sour"]
    expected = "aa"

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)
示例#9
0
 def __init__(self):
     # 诗歌生成
     self.poetry = Poetry()
     # 单个cell训练序列个数
     self.batch_size = self.poetry.batch_size
     # 所有出现字符的数量
     self.word_len = len(self.poetry.word_to_int)
     # 隐层的数量
     self.rnn_size = 128
示例#10
0
 def __init__(self):
     # 诗歌生成
     self.poetry = Poetry('data/poetry.txt')
     # 每批次训练多少首诗
     self.batch_size = self.poetry.batch_size
     # 所有出现的字符的数量
     self.word_len = self.poetry.words_len
     # lstm神经网络中间层神经元的个数
     self.lstm_size = 128
示例#11
0
  def testYIsAVowel(self):
    poetry = Poetry()
    letter = "y"

    results = poetry.isVowel(letter, 1, 3)  # y is the 2nd letter of a
                                            # 3-letter word, therefore it is a
                                            # vowel

    self.assertEqual(True, results)
示例#12
0
  def testRymmvIsALegalWord(self):
    """
    In the word, `Rymmv`, y acts as a vowel, therefore `Rymmv` is a legal word.
    """
    poetry = Poetry()
    word = "Rymmv"

    results = poetry.isLegalWord(word)

    self.assertEqual(True, results)
示例#13
0
  def testRpmmvIsNotALegalWord(self):
    """
    `Rpmmv` is not a legal word, because there are no vowels.
    """
    poetry = Poetry()
    word = "Rpmmv"

    results = poetry.isLegalWord(word)

    self.assertEqual(False, results)
示例#14
0
  def test1(self):
    poetry   = Poetry()
    poem     = ["I hope this problem",
                "is a whole lot better than",
                "this stupid haiku"]
    expected = "abc"

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)
示例#15
0
  def test4(self):
    poetry = Poetry()
    poem = ["",
            "",
            "",
            ""]
    expected = "    "

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)
示例#16
0
  def testBoughtEndingPattern(self):
    """
    The ending pattern of `bought` is `ought`.
    """
    poetry        = Poetry()
    word          = "bought"
    endingPattern = "ought"

    results = poetry.endingPattern(word)

    self.assertEqual(endingPattern, results)
示例#17
0
  def testSpyingEndingPattern(self):
    """
    The ending pattern of `spying` is `ying`, because `y` acts as a vowel.
    """
    poetry        = Poetry()
    word          = "spying"
    endingPattern = "ying"

    results = poetry.endingPattern(word)

    self.assertEqual(endingPattern, results)
示例#18
0
  def testCharacterIsNotLetter(self):
    """
    The test example tests a (possible) edge case on using ASCII calculations
    to determine whether a character is a letter.
    """
    poetry    = Poetry()
    character = "["

    results = poetry.isLetter(character)

    self.assertEqual(False, results)
示例#19
0
  def test4ppleIsNotALegalWord(self):
    """
    A legal word does not contain numbers, because it does not belong in
    a-zA-Z.
    """
    poetry = Poetry()
    word = "4pple"

    results = poetry.isLegalWord(word)

    self.assertEqual(False, results)
示例#20
0
  def testAllEndingPattern(self):
    """
    The ending pattern of `all` is itself.
    """
    poetry        = Poetry()
    word          = "all"
    endingPattern = "all"

    results = poetry.endingPattern(word)

    self.assertEqual(endingPattern, results)
示例#21
0
  def testAppleIsALegalWord(self):
    """
    `apple` is a word because...
    (1) every letter belongs in a-zA-Z,
    (2) there is at least one vowel—in this example, there are exactly 2.
    """
    poetry = Poetry()
    word   = "apple"

    results = poetry.isLegalWord(word)

    self.assertEqual(True, results)
示例#22
0
  def test5(self):
    poetry = Poetry()
    poem = ["This poem has uppercase letters",
            "In its rhyme scheme",
            "Alpha", "Blaster", "Cat", "Desert", "Elephant", "Frog", "Gulch", 
            "Horse", "Ireland", "Jam", "Krispy Kreme", "Loofah", "Moo",
            "Narf",
            "Old", "Pink", "Quash", "Rainbow", "Star", "Tour", "Uvula",
            "Very",
            "Will", "Xmas", "Young", "Zed", "deception", "comic", "grout",
            "oval", "cable", "rob", "steal", "steel", "weak"]
    expected = "abcdefghibjkblmnopqrstcuvwxyzABCbDEFG"

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)
示例#23
0
  def test3(self):
    poetry = Poetry()
    poem = ["One bright day in the middle of the night",
            "Two dead boys got up to fight",
            "Back to back they faced each other",
            "Drew their swords and shot each other",
            "",
            "A deaf policeman heard the noise",
            "And came to arrest the two dead boys",
            "And if you dont believe this lie is true",
            "Ask the blind man he saw it too"]
    expected = "aabb cdef"

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)
示例#24
0
  def test2(self):
    poetry = Poetry()
    poem = ["     ",
            "Measure your height",
            "AND WEIGHT      ",
            "said the doctor",
            "",
            "And make sure to take your pills",
            "   to   cure   your    ills",
            "Every",
            "DAY"]
    expected = " aab ccde"

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)
示例#25
0
def test_wheel_prerelease():
    module_path = fixtures_dir / 'prerelease'
    WheelBuilder.make(Poetry.create(str(module_path)), NullVenv(), NullIO())

    whl = module_path / 'dist' / 'prerelease-0.1b1-py2.py3-none-any.whl'

    assert whl.exists()
示例#26
0
def test_wheel_module():
    module_path = fixtures_dir / 'module1'
    WheelBuilder.make(Poetry.create(str(module_path)))

    whl = module_path / 'dist' / 'module1-0.1-py2.py3-none-any.whl'

    assert whl.exists()
示例#27
0
def test_wheel_package():
    module_path = fixtures_dir / 'complete'
    WheelBuilder.make(Poetry.create(str(module_path)), NullVenv(), NullIO())

    whl = module_path / 'dist' / 'my_package-1.2.3-py3-none-any.whl'

    assert whl.exists()
示例#28
0
def test_complete():
    module_path = fixtures_dir / 'complete'
    builder = CompleteBuilder(Poetry.create(module_path), NullVenv(True),
                              NullIO())
    builder.build()

    whl = module_path / 'dist' / 'my_package-1.2.3-py3-none-any.whl'

    assert whl.exists

    zip = zipfile.ZipFile(whl)

    try:
        entry_points = zip.read('my_package-1.2.3.dist-info/entry_points.txt')

        assert entry_points.decode() == """\
[console_scripts]
my-2nd-script=my_package:main2
my-script=my_package:main

"""
        wheel_data = zip.read('my_package-1.2.3.dist-info/WHEEL').decode()

        assert wheel_data == f"""\
Wheel-Version: 1.0
Generator: poetry {__version__}
Root-Is-Purelib: true
Tag: py3-none-any
"""
    finally:
        zip.close()
示例#29
0
def test_make_setup():
    poetry = Poetry.create(project('complete'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    setup = builder.build_setup()
    setup_ast = ast.parse(setup)

    setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
    ns = {}
    exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
    assert ns['packages'] == [
        'my_package',
        'my_package.sub_pkg1',
        'my_package.sub_pkg2'
    ]
    assert ns['install_requires'] == [
        'cleo (>=0.6.0.0,<0.7.0.0)'
    ]
    assert ns['entry_points'] == {
        'console_scripts': [
            'my-script = my_package:main',
            'my-2nd-script = my_package:main2',
        ]
    }
    assert ns['extras_require'] == {
        'time': [
            'pendulum (>=1.4.0.0,<2.0.0.0)'
        ]
    }
示例#30
0
def test_package():
    poetry = Poetry.create(project('complete'))

    builder = SdistBuilder(poetry)
    builder.build()

    sdist = fixtures_dir / 'complete' / 'dist' / 'my-package-1.2.3.tar.gz'

    assert sdist.exists()
示例#31
0
  def test6(self):
    poetry = Poetry()
    poem = ["                         " ,
            "                         " ,
            " This poem               " ,
            "                         " ,
            "                         " ,
            "                         " ,
            "                         " ,
            " Has lots of blank lines " ,
            "                         " ,
            "                         " ,
            "                         " ,
            "                         " ,
            "                         " ,
            "                         " ,
            "                         " ,
            " in      it              " ]
    expected = "  a    b       c"

    results = poetry.rhymeScheme(poem)

    self.assertEqual(expected, results)