Ejemplo n.º 1
0
def test_given_option_number_then_prints_line_numbers(capsys, filemaker):
    filepath = filemaker.create_file("multiline", "a\nb\nc")

    cat(filepath, number=True)

    out, err = capsys.readouterr()
    assert out == "1: a\n2: b\n3: c\n"
Ejemplo n.º 2
0
def test_given_directory_then_prints_error_message(capsys, tmpdir):
    dirname = str(tmpdir)

    cat(dirname)

    out, err = capsys.readouterr()
    assert err == "cat: {}: is a directory".format(dirname)
Ejemplo n.º 3
0
def test_given_empty_file_then_prints_nothing(capsys, filemaker):
    filepath = filemaker.create_file("emptyfile", "")

    cat(filepath)

    out, err = capsys.readouterr()
    assert out == ""
Ejemplo n.º 4
0
def concat_box_prediction_layers(box_cls, box_regression):
    box_cls_flattened = []
    box_regression_flattened = []
    # for each feature level, permute the outputs to make them be in the
    # same format as the labels. Note that the labels are computed for
    # all feature levels concatenated, so we keep the same representation
    # for the objectness and the box_regression
    for box_cls_per_level, box_regression_per_level in zip(
            box_cls, box_regression):
        N, AxC, H, W = box_cls_per_level.shape
        Ax4 = box_regression_per_level.shape[1]
        A = Ax4 // 4
        C = AxC // A
        box_cls_per_level = permute_and_flatten(box_cls_per_level, N, A, C, H,
                                                W)
        box_cls_flattened.append(box_cls_per_level)

        box_regression_per_level = permute_and_flatten(
            box_regression_per_level, N, A, 4, H, W)
        box_regression_flattened.append(box_regression_per_level)
    # concatenate on the first dimension (representing the feature levels), to
    # take into account the way the labels were generated (with all feature maps
    # being concatenated as well)
    box_cls = cat(box_cls_flattened, dim=1).reshape(-1, C)
    box_regression = cat(box_regression_flattened, dim=1).reshape(-1, 4)
    return box_cls, box_regression
Ejemplo n.º 5
0
def test_given_option_ends_then_prints_dollar_at_end_of_lines(capsys, filemaker):
    filepath = filemaker.create_file("multiline", "a\nb\nc")

    cat(filepath, ends=True)

    out, err = capsys.readouterr()
    assert out == "a$\nb$\nc$\n"
Ejemplo n.º 6
0
def test_given_multiple_files_then_prints_them_in_order(capsys, filemaker):
    first_file = filemaker.create_file("firstfile", "Roses are red")
    second_file = filemaker.create_file("secondfile", "Violets are blue")

    cat(first_file, second_file)

    out, err = capsys.readouterr()
    assert out == "Roses are red\nViolets are blue\n"
Ejemplo n.º 7
0
def test_given_single_file_then_prints_newline(capsys, filemaker):
    filepath = filemaker.create_file("poem",
        "The quick brown fox jumps over the lazy dog")

    cat(filepath)

    out, err = capsys.readouterr()
    assert out == "The quick brown fox jumps over the lazy dog\n"
def cat2(arguments):
    number_of_elements = len(arguments)
    i = 1
    while i < number_of_elements - 1:
        cat(arguments[i])
        print('\n')
        i = i + 1
    cat(arguments[i])
Ejemplo n.º 9
0
def copyFile(**kwargs):
    if Input.isParamsListEmpty(kwargs['params']):
        return

    fileList = kwargs['params']

    file = Input.getFullFileName(fileList[0])
    if not file[0]:
        print(file[1])
        return

    if len(fileList) > 2:
        print('Too many files provided\n')
        return

    kwargs['params'] = [fileList[0]]

    cwd = Input.getCwd(fileList[1])

    if os.path.exists(cwd):
        newFile = open(fileList[1], 'w')
        newFile.write(cat.cat(False, **kwargs))
        newFile.close()
    else:
        print(fileList[1] + ' : path doesn' 't exist\n')
        return

    print(str(fileList[1]) + ' has been created\n')
Ejemplo n.º 10
0
def execute_command(command):
    command_data = command.split()
    main_command = command_data[0]
    args = command_data[1:]

    all_commands = {}
    all_commands['cat'] = lambda args : cat.cat(*args)
    all_commands['duhs'] = lambda args : duhs.duhs(*args)
    all_commands[main_command](args)
Ejemplo n.º 11
0
    def test_with_valid_text_file(self):
        path = 'cat_test.txt'
        test_file = open(path, 'w')
        content = "Python is an awesome language!\nYou should try it."
        test_file.write(content)
        test_file.close()

        again = open(path, 'r')
        self.assertEqual(content, cat(again))
        os.remove(path)
Ejemplo n.º 12
0
    def test_with_valid_text_file(self):
        path = 'cat_test.txt'
        test_file = open(path, 'w')
        content = "Python is an awesome language!\nYou should try it."
        test_file.write(content)
        test_file.close()

        again = open(path, 'r')
        self.assertEqual(content, cat(again))
        os.remove(path)
Ejemplo n.º 13
0
def sort(**kwargs):
    if Input.isParamsListEmpty(kwargs['params']):
        return

    fileItems = []
    fileItems = cat.cat(False, **kwargs).split('\n')

    fileItems.sort()

    for item in fileItems:
        print(item)
Ejemplo n.º 14
0
def setCat():
    global cx, cy, themap, all_sprites_list, cat1
    cx, cy = random.randint(0,
                            len(themap[0]) - 1), random.randint(
                                0,
                                len(themap) - 1)
    while (themap[cy][cx] == 1):
        cx, cy = random.randint(0,
                                len(themap[0]) - 1), random.randint(
                                    0,
                                    len(themap) - 1)
    cat1 = cat.cat(cx, cy)
    all_sprites_list.add(cat1)
Ejemplo n.º 15
0
  def add_available_animal(self):
    Selena = cat("Selena", "calico cat", 1, 10, "female", "tuna", "loving")
    Wuffles = dog("Wuffles", "yorkshire terrier dog", 2, 12, "male", "beef-flavored dog food", "playful")
    Roddy = fish("Roddy", "goldfish", 1/2, 1, "male", "fish flakes", "docile")
    Chipper = hamster("Chipper", "syrian hamster", 3, 5, "male", "sunflower seeds", "hyper")
    Lisa = turtle("Lisa", "box turtle", 30, 2, "female", "fresh vegetables and bugs", "curious")

    self.available_animals = {
      'cat': Selena,
      'dog': Wuffles,
      'fish': Roddy,
      'hamster': Chipper,
      'turtle':  Lisa
    }
Ejemplo n.º 16
0
def main():
    # initialize a new cat
    ct = cat()
    # set the attribute
    Paar = namedtuple('Paar', ['c1', 'c2'])
    paars = []
    #    paars.append(Paar(c1 = '/tmp/de.en2014decoder_hidden.ref', c2 = '/tmp/de.en2015decoder_hidden.ref'))
    paars.append(
        Paar(c1='/tmp/de.en2014decoder_hidden.s1',
             c2='/tmp/de.en2015decoder_hidden.s1'))
    paars.append(
        Paar(c1='/tmp/de.en2014decoder_hidden.s2',
             c2='/tmp/de.en2015decoder_hidden.s2'))
    # concat the paar
    for paar in paars:
        ct.forward(paar.c1, paar.c2)
Ejemplo n.º 17
0
def results_array():
    if request.method == 'POST':
        number = int(
            request.form['number']
        )  # saves value of number chosen by user as variable 'number'
        output = cat_mouse(number)  # saves results list to variable 'output'
        dogs = dog(number)  # saves number of dogs to variable 'dog'
        cats = cat(number)  # saves number of cats to variable 'cats'
        catm = camo(number)  # saves number of cat and mice to variable 'catm'
        mice = mouse(number)  # saves number of mice to variable 'mice'
        return render_template("Result.html",
                               text=output,
                               dog=dogs,
                               cats=cats,
                               mice=mice,
                               catm=catm)
Ejemplo n.º 18
0
 def test_cat_with_existing_file(self):
     self.assertEqual(self.contents, cat(self.fileName))
Ejemplo n.º 19
0
def test_given_wrong_file_name_then_prints_error_message(capsys):
    cat('superduperfilename')

    out, err = capsys.readouterr()
    assert err == "cat: superduperfilename: No such file or directory"
Ejemplo n.º 20
0
def cat2(arguments):
    length = len(arguments)
    for index in range(1, length):
        cat(arguments[index])
        if index != length - 1:
            print()
Ejemplo n.º 21
0
if __name__ == '__main__':
    print 'absolute path'
    from cat import cat
else:
    print 'relative path'
    from .cat import cat
def dog():
    print 'wang wang wang'

dog()
cat()
Ejemplo n.º 22
0
 def test_if_is_readen_from_file(self):
     self.assertEqual(self.text,cat(self.filename))
Ejemplo n.º 23
0
def cat_multiple(args):
    for i in range(1, len(args)):
        cat(args[i])
        if i != len(args) - 1:
            print(" ")
Ejemplo n.º 24
0
 def test_with_invalid_text_file(self):
     with self.assertRaises(BaseException):
         test_file = None
         cat(test_file)
Ejemplo n.º 25
0
 def put_cat(self):
     c1 = cat.cat()
     return c1
Ejemplo n.º 26
0
 def test_cat_with_nonExisting_file(self):
     randomName = str(uuid.uuid4())
     catResult = "File {} not found!".format(randomName)
     self.assertEqual(catResult, cat(randomName))
Ejemplo n.º 27
0
def main():
    print(sys.argv[1], sys.argv[2])
    generate_numbers(sys.argv[1], sys.argv[2])
    cat(sys.argv[1])
Ejemplo n.º 28
0
from cat import cat

cat = cat('Shadow', 'azuis')

cat.miar()
cat.agachar()
Ejemplo n.º 29
0
from pet import pet
from dog import dog
from cat import cat

mister_dog = dog("mister", True)
print(mister_dog.chasesCats())
print(mister_dog.getName())
m_cat = cat("polly", "yes")
Ejemplo n.º 30
0
 def test_with_invalid_text_file(self):
     with self.assertRaises(BaseException):
         test_file = None
         cat(test_file)
Ejemplo n.º 31
0
from cat import cat
from smallcat import smallcat

#实例化类,不用传self
my_cat = cat('柠檬', '2岁')
her_cat = cat('酸菜', '5岁')
his_cat = cat('冬瓜', '3岁')

#访问属性

print('我的猫名字叫', my_cat.name.title())
print('我的猫今年', str(my_cat.age))

#调用方法
my_cat.sit()
my_cat.eat()
my_cat.play()

print('我们总共有', my_cat.name.title(), her_cat.name.title(), his_cat.name.title(),
      '的猫')
her_cat.play()
my_cat.eat()
his_cat.sit()

#调用父类
small_cat = smallcat('南瓜', '0.3岁')
small_cat.eat()
print(small_cat.name.title(), '现在已经', small_cat.age.title())
small_cat.milk()
Ejemplo n.º 32
0
 def test_cat_with_existing_file(self):
     actual = cat(self.filename)
     self.assertEqual(self.content, actual)
Ejemplo n.º 33
0
 def test_multiple_concat(self):
     correct = cat("Megatron.txt")
     self.assertEqual(self.contents, correct)
Ejemplo n.º 34
0
def cat2(arguments):
    for i in arguments:
        cat(i)
        print()
Ejemplo n.º 35
0
'''
多态:一种事物的多种形态
最终目标:人可以喂任何一种动物

'''
from cat import cat
from mouse import mouse
from person import person

tom = cat("tom")
jerry = mouse("jerry")
tom.eat()
jerry.eat()
print(tom.name)

#定义一个人,喂动物
per = person()
per.feedAnimal(tom)
per.feedAnimal(jerry)

per.findAnimal(tom)
#思考:100种动物,也都有name属性和eat方法
#可创建一个父类,都继承自父类。

#定义一个人类,可以喂猫和老鼠吃东西
Ejemplo n.º 36
0
from sys import argv
import cat
import echo
import head
import sort
import tail

if argv[1] == '-c':
    cat.cat(argv[2])
elif argv[1] == '-e':
    echo.echo(argv[2])
elif argv[1] == '-h':
    head.head(argv[2])
elif argv[1] == '-s':
    sort.sort(argv[2])
elif argv[1] == '-t':
    tail.tail(argv[2])
Ejemplo n.º 37
0
def history(**kwargs):
    kwargs['params'] = ['historylist']
    cat.cat(**kwargs)
Ejemplo n.º 38
0
def cat2(arguments):
    for i in range(1, len(arguments)):
        print(cat(arguments[i]))
Ejemplo n.º 39
0
def main():
    for i in range(1, len(sys.argv)):
        cat(sys.argv[i])
        print()